Thread: initializer element is not constant...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by John Connor View Post
    Ok.
    As a matter of fact I want them to be global and static as well.
    I read about the #define environment to create macros but I'm not sure if
    Code:
    #define t_max  t_max 2.0*3.1415926535897932384626433832795
    results in a floating point t_max or what.

    Thanks.
    That's going to get you a lot of errors.

    #define macros are just search-n-replace; if you did
    Code:
    #define t_max (2.0*3.1415926535897932384626433832795)
    would simply make the preprocessor remove all occurrences of the token t_max and replace it with that ... thing on the right. The compiler would never see a variable t_max at all.

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    20
    Quote Originally Posted by tabstop View Post
    That's going to get you a lot of errors.

    #define macros are just search-n-replace; if you did
    Code:
    #define t_max (2.0*3.1415926535897932384626433832795)
    would simply make the preprocessor remove all occurrences of the token t_max and replace it with that ... thing on the right. The compiler would never see a variable t_max at all.

    Thanks I realised my mistake in the previos reply and removed the t_max t_max...

    Now, if I use the expression
    Code:
    #define t_max 2.0*3.1415926535897932384626433832795
    Can i call t_max expecting it to be double precision?

    Thanks

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by John Connor View Post
    Thanks I realised my mistake in the previos reply and removed the t_max t_max...

    Now, if I use the expression
    Code:
    #define t_max 2.0*3.1415926535897932384626433832795
    Can i call t_max expecting it to be double precision?

    Thanks
    Yes, in that any constant with a decimal point in it in a C program is double unless you tag it otherwise: 1.0 is double, 1.0f is float.
    Last edited by tabstop; 02-01-2008 at 12:24 PM. Reason: fixed

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    20
    Quote Originally Posted by tabstop View Post
    Yes, in that any constant with a decimal point in it in a C program is double unless you tag it otherwise: 1.0 is double, 1.0f is float.
    Thanks a lot! That really helped me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM