dollar sign in macros

Collapse
This topic is closed.
X
X
Collapse
+ More Options
Posts
 
  • Time
  • Show
Clear All
new posts
  • Digital Puer

    dollar sign in macros

    I've inherited some code where the coder placed dollar signs in
    his preprocessor macros. What is the significance of the
    dollar signs ($) ?

    Example:
    #define ALLOCATE(task,p ointer) \
    { \
    long task$; \
    if (task == FOO) { \
    task$ = ZERO); \
    } else task$ = task; \
    switch (task$) {

    etc.

  • matevzb

    #2
    Re: dollar sign in macros

    Digital Puer wrote:
    I've inherited some code where the coder placed dollar signs in
    his preprocessor macros. What is the significance of the
    dollar signs ($) ?
    I'm not a Standard expert, but I think $ is disallowed in an
    identifier:
    ---
    3.1.2 Identifiers
    <snip>
    An identifier is a sequence of nondigit characters (including the
    underscore _ and the lower-case and upper-case letters) and digits. The
    first character shall be a nondigit character.
    <snip>
    ---

    <OT>
    That said, $ does have a special treatment on OpenVMS and maybe other
    VAXen systems. I'm not sure what it does however...
    </OT>

    --
    WYCIWYG - what you C is what you get

    Comment

    • loic-dev@gmx.net

      #3
      Re: dollar sign in macros

      Hello,
      I've inherited some code where the coder placed dollar signs in
      his preprocessor macros. What is the significance of the
      dollar signs ($) ?
      >
      Example:
      #define ALLOCATE(task,p ointer) \
      { \
      long task$; \
      if (task == FOO) { \
      task$ = ZERO); \
      } else task$ = task; \
      switch (task$) {
      >
      etc.
      in your above example, the '$' sign has no special meaning. It's just
      used as another character for the variable name, which is called here
      "task$". This may be a strange name, but unless I am mistaken, this is
      a perfectly valid name.

      The coder may have use the "$" sign to define a convention of its own.
      Unless you have some documentation (code design, comments in the code
      etc.) about this convention, you have to induce it (if one is defined)
      from the source you received. Or just you take that "$"-name as it is.

      HTH,
      Loic.

      Comment

      • Mark McIntyre

        #4
        Re: dollar sign in macros

        On 4 Dec 2006 14:03:55 -0800, in comp.lang.c , "Digital Puer"
        <digital_puer@h otmail.comwrote :
        >I've inherited some code where the coder placed dollar signs in
        >his preprocessor macros. What is the significance of the
        >dollar signs ($) ?
        reminds me of the old VAX/VMS system routines/variables.
        --
        Mark McIntyre

        "Debugging is twice as hard as writing the code in the first place.
        Therefore, if you write the code as cleverly as possible, you are,
        by definition, not smart enough to debug it."
        --Brian Kernighan

        Comment

        • Ben Pfaff

          #5
          Re: dollar sign in macros

          loic-dev@gmx.net writes:
          in your above example, the '$' sign has no special meaning. It's just
          used as another character for the variable name, which is called here
          "task$". This may be a strange name, but unless I am mistaken, this is
          a perfectly valid name.
          Not in ISO C, either C89 or C99. In C99, you can specify a
          dollar sign using a universal character name, but it doesn't
          *look* like a dollar sign then.
          --
          "I ran it on my DeathStation 9000 and demons flew out of my nose." --Kaz

          Comment

          • loic-dev@gmx.net

            #6
            Re: dollar sign in macros

            Hi Ben,
            in your above example, the '$' sign has no special meaning. It's just
            used as another character for the variable name, which is called here
            "task$". This may be a strange name, but unless I am mistaken, this is
            a perfectly valid name.
            >
            Not in ISO C, either C89 or C99. In C99, you can specify a
            dollar sign using a universal character name, but it doesn't
            *look* like a dollar sign then.
            Yeah thanks. I had a doubt about this, I just checked out the
            standard... I should have used the '-pedantic' flag, when I checked
            with my compiler ;-) Which is by no means a proof, BTW... Next time, I
            look the standard first, then I post :-D

            Cheers,
            Loic.

            Comment

            • Spiros Bousbouras

              #7
              Re: dollar sign in macros

              Digital Puer wrote:
              I've inherited some code where the coder placed dollar signs in
              his preprocessor macros. What is the significance of the
              dollar signs ($) ?
              >
              Example:
              #define ALLOCATE(task,p ointer) \
              { \
              long task$; \
              if (task == FOO) { \
              task$ = ZERO); \
              } else task$ = task; \
              switch (task$) {
              >
              etc.
              As others have said $ is probably part of the name of
              the variable and not allowed in standard C. Some compilers
              allow as an extension $ to be part of an identifier name ;
              for example gcc.

              Comment

              • santosh

                #8
                Re: dollar sign in macros

                Digital Puer wrote:
                I've inherited some code where the coder placed dollar signs in
                his preprocessor macros. What is the significance of the
                dollar signs ($) ?
                >
                Example:
                #define ALLOCATE(task,p ointer) \
                { \
                long task$; \
                if (task == FOO) { \
                task$ = ZERO); \
                } else task$ = task; \
                switch (task$) {
                >
                etc.
                This is a gcc extension. Other compilers may also have this feature.

                Comment

                • Christopher Benson-Manica

                  #9
                  Re: dollar sign in macros

                  Digital Puer <digital_puer@h otmail.comwrote :
                  I've inherited some code where the coder placed dollar signs in
                  his preprocessor macros. What is the significance of the
                  dollar signs ($) ?
                  That someone is using a C implementation to preprocess Perl source?
                  As others have noted the $ is not a valid identifier character. It
                  should be possible to run this code through the preprocessor with your
                  implementation and see what it looks like; that may give you a clue as
                  to what is going on. How that might be accomplished is a question for
                  a different newsgroup.

                  --
                  C. Benson Manica | I *should* know what I'm talking about - if I
                  cbmanica(at)gma il.com | don't, I need to know. Flames welcome.

                  Comment

                  • Digital Puer

                    #10
                    Re: dollar sign in macros


                    santosh wrote:
                    Digital Puer wrote:
                    I've inherited some code where the coder placed dollar signs in
                    his preprocessor macros. What is the significance of the
                    dollar signs ($) ?

                    Example:
                    #define ALLOCATE(task,p ointer) \
                    { \
                    long task$; \
                    if (task == FOO) { \
                    task$ = ZERO); \
                    } else task$ = task; \
                    switch (task$) {

                    etc.
                    >
                    This is a gcc extension. Other compilers may also have this feature.

                    The original programmer used Microsoft VC++ to write his C code.
                    He is a chemist by training, and he is kind of an old guy (about 60).

                    Another poster said that the code reminded him of VMS code,
                    so I wonder if the original programmer was doing something
                    along those lines.

                    Comment

                    • Keith Thompson

                      #11
                      Re: dollar sign in macros

                      Christopher Benson-Manica <ataru@ukato.fr eeshell.orgwrit es:
                      Digital Puer <digital_puer@h otmail.comwrote :
                      >I've inherited some code where the coder placed dollar signs in
                      >his preprocessor macros. What is the significance of the
                      >dollar signs ($) ?
                      >
                      That someone is using a C implementation to preprocess Perl source?
                      [...]

                      Not likely. The "identifier " in question was "task$"; Perl would use
                      "$task".

                      --
                      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                      San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
                      We must do something. This is something. Therefore, we must do this.

                      Comment

                      • Joseph Huber

                        #12
                        Re: dollar sign in macros

                        In article <1165291965.250 100.62140@73g20 00cwn.googlegro ups.com>, "Digital Puer" <digital_puer@h otmail.comwrite s:
                        >
                        Another poster said that the code reminded him of VMS code,
                        so I wonder if the original programmer was doing something
                        along those lines.
                        I think it's just the programmers habit to use $ in identifiers.
                        True, VMS C compilers allow $ (and gcc probably to cover programs
                        written for VMS), but names containing $ in VMS are reserved to the system
                        vendor (and registered third party software), to make them unique.

                        So $s in user programs violate both, C and VMS standards.

                        --
                        Joseph Huber , Muenchen,German y: http://www.huber-joseph.de/

                        Comment

                        • pete

                          #13
                          Re: dollar sign in macros

                          Joseph Huber wrote:
                          >
                          In article <1165291965.250 100.62140@73g20 00cwn.googlegro ups.com>, "Digital Puer" <digital_puer@h otmail.comwrite s:

                          Another poster said that the code reminded him of VMS code,
                          so I wonder if the original programmer was doing something
                          along those lines.
                          >
                          I think it's just the programmers habit to use $ in identifiers.
                          True, VMS C compilers allow $ (and gcc probably to cover programs
                          written for VMS), but names containing $ in VMS are reserved to the system
                          vendor (and registered third party software), to make them unique.
                          >
                          So $s in user programs violate both, C and VMS standards.
                          Whenever I see posted C programs that use reserved identifiers,
                          it reminds me of a time when I read system header files
                          to see what proffessional code looked like,
                          so that I could imitate the style (a misconception on my part).

                          --
                          pete

                          Comment

                          • Christopher Benson-Manica

                            #14
                            Re: dollar sign in macros

                            pete <pfiland@mindsp ring.comwrote:
                            Whenever I see posted C programs that use reserved identifiers,
                            it reminds me of a time when I read system header files
                            to see what proffessional code looked like,
                            so that I could imitate the style (a misconception on my part).
                            A misconception in more ways than one, given what some of that
                            "profession al" code looks like :-)

                            --
                            C. Benson Manica | I *should* know what I'm talking about - if I
                            cbmanica(at)gma il.com | don't, I need to know. Flames welcome.

                            Comment

                            • Random832

                              #15
                              Re: dollar sign in macros

                              2006-12-05 <wZrLMQvhIVAk@v ms.mppmu.mpg.de >,
                              Joseph Huber wrote:
                              In article <1165291965.250 100.62140@73g20 00cwn.googlegro ups.com>, "Digital Puer" <digital_puer@h otmail.comwrite s:
                              >>
                              >Another poster said that the code reminded him of VMS code,
                              >so I wonder if the original programmer was doing something
                              >along those lines.
                              >
                              I think it's just the programmers habit to use $ in identifiers.
                              True, VMS C compilers allow $ (and gcc probably to cover programs
                              written for VMS), but names containing $ in VMS are reserved to the system
                              vendor (and registered third party software), to make them unique.
                              >
                              So $s in user programs violate both, C and VMS standards.
                              Is \u0024 allowed in identifiers?

                              Is there a list of what UCNs are and are not allowed in identifiers?

                              Comment

                              Working...