Thread: #define question

  1. #1
    Registered User
    Join Date
    Nov 2010

    #define question

    I am new to C and have a simple question. I use Visual Studio 2008 C++ Express edition. I added a

    #define ONE 1;

    statement before main(). Within my main definition I tried to

    printf("%d", ONE);

    When I compiled it threw an error. I then added an

    int one = ONE;
    printf("%d", one);

    statement and it compiled fine. I am deducing that constants cannot be used directly in functions, but, must be applied to some sort of calculation first. Is that correct?

  2. #2
    Join Date
    Aug 2010
    Ontario Canada
    It may be in the printf() case but it certainly isn't the rule in C...
    Most windows functions have massive constants defined in that way.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Macros are just text substitution. The reason you get an error is because of this:
    #define ONE 1;
    Get rid of that, and you should be fine.

    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Thanks for pointing that out. Much appreciated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Restaurant Point-of-Sale Application: Help?!
    By matt.s in forum C Programming
    Replies: 14
    Last Post: 04-16-2010, 05:36 PM
  2. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  3. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  4. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM

Tags for this Thread