#define question

This is a discussion on #define question within the C Programming forums, part of the General Programming Boards category; I am new to C and have a simple question. I use Visual Studio 2008 C++ Express edition. I added ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    5

    #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
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    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
    Posts
    14,826
    Macros are just text substitution. The reason you get an error is because of this:
    Code:
    #define ONE 1;
    Get rid of that, and you should be fine.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    5
    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, 06: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, 10:36 AM
  4. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM

Tags for this Thread


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