#Defining

This is a discussion on #Defining within the C Programming forums, part of the General Programming Boards category; Hi, Just a quick question - I am currently debugging a large quantity of code (a 3G Protocol Stack). Something ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    20

    #Defining

    Hi,

    Just a quick question - I am currently debugging a large quantity of code (a 3G Protocol Stack).

    Something thats bothering me - if a #define is referenced in two files with either the same value/different values, will this cause a complication error because the pre-processor will see two different values?

    pc_doctor

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,753
    Quote Originally Posted by pc_doctor
    Something thats bothering me - if a #define is referenced in two files with either the same value/different values, will this cause a complication error because the pre-processor will see two different values?
    It sounds like the answer is no, but what exactly do you mean by "a #define is referenced in two files with either the same value/different values"? Providing an example would be a good idea. (Once you are able to come up with an example, you can then test it for yourself, assuming that by "complication error" you mean compile error.)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    452
    pretty sure that he means:

    "will it cause an error to define two different values to the same name as long as it is done in two different files?"

    ie, in file 1

    #DEFINE foo bar

    and in file 2

    #DEFINE foo 5

    Even if it doesn't, it should probably be avoided for the sake of clarity of the code.
    Last edited by KBriggs; 05-25-2010 at 08:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Defining const in a class
    By g4j31a5 in forum C++ Programming
    Replies: 5
    Last Post: 11-20-2006, 10:27 AM
  2. Defining matricies
    By rich999 in forum C++ Programming
    Replies: 6
    Last Post: 12-02-2005, 06:59 PM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21