Compiler Directives Not Working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shane.tietjen@gmail.com

    #1

    Compiler Directives Not Working

    Working in VS 2003.

    in a header file:

    [test.h]

    #ifdef _UNUSED_NAME_32 23458 //this is not defined anywhere at anytime
    #define TEST123 6789
    #endif

    [\test.h]

    in the implementation file:

    [test.cpp]

    \\the value of TEST123 will be 6789 or whatever value is assigned to it
    even though _UNUSED_NAME_32 23458 was never defined and is not present
    in any other files.

    [\test.cpp]

    Also, if you do:
    #ifndef _UNUSED_NAME_32 23458
    #define TEST123 0
    #endif

    Insert this prior to the other one(so you test for not defined before
    defined), TEST123 will have a value of 0 and not 6789.

    No errors or warnings.

    It is almost as if the variable you testing( _UNUSED_NAME_32 23458 which
    is never defined at any time) is in an unknown state at the time you
    test it.

    What is going on here?

  • Victor Bazarov

    #2
    Re: Compiler Directives Not Working

    shane.tietjen@g mail.com wrote:[color=blue]
    > Working in VS 2003.[/color]

    Perhaps you should ask in 'microsoft.publ ic.vc.language' ...
    [color=blue]
    > in a header file:
    >
    > [test.h]
    >
    > #ifdef _UNUSED_NAME_32 23458 //this is not defined anywhere at anytime
    > #define TEST123 6789
    > #endif
    >
    > [\test.h]
    >
    > in the implementation file:
    >
    > [test.cpp]
    >
    > \\the value of TEST123 will be 6789 or whatever value is assigned to it
    > even though _UNUSED_NAME_32 23458 was never defined and is not present
    > in any other files.[/color]

    By _definition_ if 'TEST123' has the value 6789 (or whatever), it means
    that either 'TEST123' is defined _elsewhere_ *as well* as here, or that
    "_UNUSED_NAME_3 223458" macro is in fact _defined_ and that's how the C++
    preprocessor knows to define 'TEST123".

    What you're trying to doubt here is the very basic functionality of the
    preprocessor. I am _sure_ it's you who's made the mistake. Are you sure
    it's "ifdef" and not "ifndef"?.. .
    [color=blue]
    >
    > [\test.cpp]
    >
    > Also, if you do:
    > #ifndef _UNUSED_NAME_32 23458
    > #define TEST123 0
    > #endif
    >
    > Insert this prior to the other one(so you test for not defined before
    > defined), TEST123 will have a value of 0 and not 6789.
    >
    > No errors or warnings.
    >
    > It is almost as if the variable you testing( _UNUSED_NAME_32 23458 which
    > is never defined at any time) is in an unknown state at the time you
    > test it.
    >
    > What is going on here?
    >[/color]

    Impossible to say. Your code fragments do not carry enough information.
    You're asking for a rather big leap from those fragments to the notion
    that everything else is OK, and you didn't screw up somehow. I'd rather
    believe the compiler.

    V
    --
    Please remove capital As from my address when replying by mail

    Comment

    • red floyd

      #3
      Re: Compiler Directives Not Working

      shane.tietjen@g mail.com wrote:[color=blue]
      > Working in VS 2003.
      >
      > in a header file:
      >
      > [test.h]
      >
      > #ifdef _UNUSED_NAME_32 23458 //this is not defined anywhere at anytime[/color]

      _UNUSED_NAME_32 23458 is reserved to the implementation. You can't use
      it in your code.
      [color=blue]
      > #define TEST123 6789
      > #endif
      >[/color]

      Comment

      • Jay_Nabonne

        #4
        Re: Compiler Directives Not Working

        On Wed, 08 Feb 2006 09:00:48 -0800, shane.tietjen wrote:
        [color=blue]
        > Working in VS 2003.
        >
        > in a header file:
        >
        > [test.h]
        >
        > #ifdef _UNUSED_NAME_32 23458 //this is not defined anywhere at anytime
        > #define TEST123 6789
        > #endif
        >
        > [\test.h]
        >
        > in the implementation file:
        >
        > [test.cpp]
        >
        > \\the value of TEST123 will be 6789 or whatever value is assigned to it
        > even though _UNUSED_NAME_32 23458 was never defined and is not present
        > in any other files.
        >[/color]

        Put

        #undef _UNUSED_NAME_32 23458

        right before the #ifdef in test.h. If that fixes it, then
        _UNUSED_NAME_32 23458 is defined *somewhere*. (Preprocessor defines in the
        project settings perhaps?)

        Also, what if you change it to

        #ifdef _UNUSED_NAME_32 23458foo

        ? Does it still behave the same?

        - Jay

        Comment

        • Howard

          #5
          Re: Compiler Directives Not Working


          <shane.tietjen@ gmail.com> wrote in message
          news:1139418048 .712977.215030@ g47g2000cwa.goo glegroups.com.. .[color=blue]
          > Working in VS 2003.
          >
          > in a header file:
          >
          > [test.h]
          >
          > #ifdef _UNUSED_NAME_32 23458 //this is not defined anywhere at anytime
          > #define TEST123 6789
          > #endif
          >
          > [\test.h]
          >
          > in the implementation file:
          >
          > [test.cpp]
          >
          > \\the value of TEST123 will be 6789 or whatever value is assigned to it
          > even though _UNUSED_NAME_32 23458 was never defined and is not present
          > in any other files.
          >
          > [\test.cpp]
          >
          > Also, if you do:
          > #ifndef _UNUSED_NAME_32 23458
          > #define TEST123 0
          > #endif
          >
          > Insert this prior to the other one(so you test for not defined before
          > defined), TEST123 will have a value of 0 and not 6789.
          >
          > No errors or warnings.
          >
          > It is almost as if the variable you testing( _UNUSED_NAME_32 23458 which
          > is never defined at any time) is in an unknown state at the time you
          > test it.
          >
          > What is going on here?
          >[/color]

          You don't show how you're checking the value of TEST123. How do you know
          its value if it hasn't been defined? Testing for a specific value may not
          be a valid test if it is never defined in the first place. (I'm not sure if
          that's mandated by the standard, or an implementation detail, though.)

          -Howard



          Comment

          • shane.tietjen@gmail.com

            #6
            Re: Compiler Directives Not Working

            I thought I was very clear. TEST123 and _UNUSED_NAME_32 23458 are not
            defined anywhere in my code nor are they present in any file on the
            system. This means that there is no possible way they could be
            defined. Not defined.

            I understand the compiler is smarter than I am. Thats why I use it
            instead of writing Assembly.

            Comment

            • shane.tietjen@gmail.com

              #7
              Re: Compiler Directives Not Working

              Could you explain what you mean by "reserved" and by "You can't use it
              in your code."?
              Thanks

              Comment

              • shane.tietjen@gmail.com

                #8
                Re: Compiler Directives Not Working

                I have tried the #undef solution before and it produced the same
                results. But it IS NOT defined anywhere on the local machine in any
                file. I know this becaue I just made up the name with a bunch of
                random numbers and then searched for it.

                And yes, it will behave the same no matter what name you choose.

                Comment

                • Ben Pope

                  #9
                  Re: Compiler Directives Not Working

                  shane.tietjen@g mail.com wrote:[color=blue]
                  > Could you explain what you mean by "reserved" and by "You can't use it
                  > in your code."?[/color]

                  The standard says that identifiers that start with an underscore
                  followed by a capital alpha character are reserved for the implementation.

                  As are identifiers prefixed with double underscore.

                  This means you have undefined behaviour, regardless of how likely that
                  identifier is likely to appear in the implementation.

                  Ben Pope
                  --
                  I'm not just a number. To many, I'm known as a string...

                  Comment

                  • shane.tietjen@gmail.com

                    #10
                    Re: Compiler Directives Not Working

                    <Quote>
                    You don't show how you're checking the value of TEST123. How do you
                    know
                    its value if it hasn't been defined? Testing for a specific value may
                    not
                    be a valid test if it is never defined in the first place. (I'm not
                    sure if
                    that's mandated by the standard, or an implementation detail, though.)

                    -Howard
                    <\Quote>

                    I check it using the debugger at runtime. I searched every file on the
                    local machine and "TEST123" and "_UNUSED_NAME_x xxx" not listed as being
                    part of any other file other than the lines I showed you in the .h file
                    and .cpp file we are dealing with.

                    Comment

                    • shane.tietjen@gmail.com

                      #11
                      Re: Compiler Directives Not Working

                      <quote>[color=blue]
                      > Could you explain what you mean by "reserved" and by "You can't use it
                      > in your code."?[/color]

                      The standard says that identifiers that start with an underscore
                      followed by a capital alpha character are reserved for the
                      implementation.

                      As are identifiers prefixed with double underscore.


                      This means you have undefined behaviour, regardless of how likely that
                      identifier is likely to appear in the implementation.
                      <quote>

                      Okay I accept that. I wasn't trying to confuse anyone with the name.
                      Truth is, the name doesn't matter so assume my original problem without
                      the "_" at the beginning. Sorry for any confusion.

                      Comment

                      • Victor Bazarov

                        #12
                        Re: Compiler Directives Not Working

                        Ben Pope wrote:[color=blue]
                        > shane.tietjen@g mail.com wrote:
                        >[color=green]
                        >> Could you explain what you mean by "reserved" and by "You can't use it
                        >> in your code."?[/color]
                        >
                        >
                        > The standard says that identifiers that start with an underscore
                        > followed by a capital alpha character are reserved for the implementation.
                        >
                        > As are identifiers prefixed with double underscore.[/color]

                        Actually, as are identifiers _containing_ double underscores (17.4.3.1.2).
                        [color=blue]
                        > This means you have undefined behaviour, regardless of how likely that
                        > identifier is likely to appear in the implementation.[/color]

                        V
                        --
                        Please remove capital As from my address when replying by mail

                        Comment

                        • Howard

                          #13
                          Re: Compiler Directives Not Working


                          <shane.tietjen@ gmail.com> wrote in message
                          news:1139430171 .126414.298640@ z14g2000cwz.goo glegroups.com.. .[color=blue]
                          > <Quote>
                          > You don't show how you're checking the value of TEST123. How do you
                          > know
                          > its value if it hasn't been defined? Testing for a specific value may
                          > not
                          > be a valid test if it is never defined in the first place. (I'm not
                          > sure if
                          > that's mandated by the standard, or an implementation detail, though.)
                          >
                          > -Howard
                          > <\Quote>
                          >
                          > I check it using the debugger at runtime. I searched every file on the
                          > local machine and "TEST123" and "_UNUSED_NAME_x xxx" not listed as being
                          > part of any other file other than the lines I showed you in the .h file
                          > and .cpp file we are dealing with.
                          >[/color]

                          I'd question the debugger, then. Try actually using code or more
                          preprocessor directives to test if it's defined, and what its value is. I
                          bet it's simply not defined, which is confusing the debugger. Try something
                          like this to test:

                          // in header file:
                          #ifdef _UNUSED_NAME_32 23458 //this is not defined anywhere at anytime
                          #define TEST123 6789
                          #endif

                          // in a function somewhere in a file which includes that header:
                          #ifdef TEST123
                          int testInt = TEST123;
                          #else
                          int testInt = 0;
                          #endif
                          // Now, check or display the value of testInt!

                          -Howard




                          Comment

                          • Victor Bazarov

                            #14
                            Re: Compiler Directives Not Working

                            shane.tietjen@g mail.com wrote:[color=blue]
                            > I thought I was very clear. TEST123 and _UNUSED_NAME_32 23458 are not
                            > defined anywhere in my code nor are they present in any file on the
                            > system. This means that there is no possible way they could be
                            > defined. Not defined.
                            >
                            > I understand the compiler is smarter than I am. Thats why I use it
                            > instead of writing Assembly.[/color]

                            No, the compiler is not smarter. It's just more careful at following
                            the rules imposed on it.

                            Read the FAQ 5.8, and follow its recommendations . Then we can talk. So
                            far you're just too frustrated about your problem to hear what others are
                            telling you.

                            V
                            --
                            Please remove capital As from my address when replying by mail

                            Comment

                            • Victor Bazarov

                              #15
                              Re: Compiler Directives Not Working

                              shane.tietjen@g mail.com wrote:[color=blue]
                              > <quote>
                              >[color=green]
                              >>Could you explain what you mean by "reserved" and by "You can't use it
                              >>in your code."?[/color]
                              >
                              >
                              > The standard says that identifiers that start with an underscore
                              > followed by a capital alpha character are reserved for the
                              > implementation.
                              >
                              > As are identifiers prefixed with double underscore.
                              >
                              >
                              > This means you have undefined behaviour, regardless of how likely that
                              > identifier is likely to appear in the implementation.
                              > <quote>
                              >
                              > Okay I accept that. I wasn't trying to confuse anyone with the name.
                              > Truth is, the name doesn't matter so assume my original problem without
                              > the "_" at the beginning. Sorry for any confusion.[/color]

                              No. We won't assume anything. Assumption is the mother of all f***-ups.

                              Post complete minimal code that demonstrates your problem.

                              V
                              --
                              Please remove capital As from my address when replying by mail

                              Comment

                              Working...