Re: pls expand this macro



In article <4364C9B9.A1BE52CF@xxxxxxxxxxxxxxxxxxx>,
sathyashrayan <sathyashrayan@xxxxxxxxxxxxxxxxxxx> wrote:

>#define plural_text(n) &"s"[(1 == (n))]

>1) I try to understand the two macros plural_text and plural_text2.
>array subscripting is commutative
>so in the above we could expand the macros as plural_text n[1] = "s" .

No, there is no assignment done. (1 == (n)) is an expression which
produces a value which is either 0 or 1, and the string "s" is indexed
at that offset, and the address (&) of the result is taken.
&"s"[0] is a pointer to the 's' character in a string, but
&"s"[1] is a pointer to the nul that follows the 's'.

In other words the result is either the string "s" or the empty string.

>3) << operator in the macro plural_text2 used to move the string to the
>second one, in the above case
>it is "s". Correct?

No, treat the inside as an expression again and look at the offsets
into the string.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
.



Relevant Pages

  • Re: works on console but not when writing to a string or file
    ... I would think that what's strange is that your code doesn't work, not that some other code does. ... System.Console.Write(Encoding.ASCII.GetString(data, offset, ... in the outputdata string the last packets gets chopped off. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I find strings with wildcards?
    ... offset in a string. ... set match = match + 1 ...
    (comp.lang.pascal.delphi.misc)
  • Re: after ids
    ... I have no string opinion yet, I'd just like to know your analysis. ... Normally this Tcl_Obj probably won't shimmer, ... objPtr->internalRep would have an integer value that we use as an offset ... Then when we want to acccess a TimerHandler struct for after id or after ...
    (comp.lang.tcl)
  • Re: SQL Logic Question
    ... I have a COLOR and OFFSET that is used as the reference. ... from the main dtaTable (or dtaRS). ... Sub CalculateColumnSums() ... Dim RsDates as cRecordset, SQL as String, i As Long ...
    (microsoft.public.vb.database)
  • Re: Base64Encoder for Stream
    ... Now Im converting stream to String, Im encoding and then string to ... offset: shortint; ... end;// base64, mime ...
    (borland.public.delphi.thirdpartytools.general)