Thread: #Defining

  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
    28,413
    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.)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    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, 11:27 AM
  2. Defining matricies
    By rich999 in forum C++ Programming
    Replies: 6
    Last Post: 12-02-2005, 07: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