DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: #define statement

  1. #1
    Chad Gorshing Guest

    #define statement


    The company that I work for has many statements for global variables they
    use the #define statement:

    #define GLOBAL_VARIABLES

    most of the time. My question is that I see alot of the same variable defined
    many times throughout many files. I would have used the:

    #ifndef
    #define GLOBAL_VARIABLES
    #endif

    What happens if you define a variable that is already defined?

    Thanks for any help.

    Chad Gorshing

  2. #2
    Danny Kalev Guest

    Re: #define statement

    it depends on what you mean by 'variable'. If you mean a real object or
    variable, the result is a compile time or link time error. If you meant
    a macro being #defined more than once, the result depends on whether the
    second occurrence of the macro is identical to the first. If it is, some
    compilers will accepts it silently whereas others will issue a warning.
    If the #define directive defines a new value to a previously #defined
    macro, the result is a compiler's diagnostic -- either an error or a
    warning.

    Danny

    Chad Gorshing wrote:
    >
    > The company that I work for has many statements for global variables they
    > use the #define statement:
    >
    > #define GLOBAL_VARIABLES
    >
    > most of the time. My question is that I see alot of the same variable defined
    > many times throughout many files. I would have used the:
    >
    > #ifndef
    > #define GLOBAL_VARIABLES
    > #endif
    >
    > What happens if you define a variable that is already defined?
    >
    > Thanks for any help.
    >
    > Chad Gorshing


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center