Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Compare to a defined constants in C?

Reply
Thread Tools

Compare to a defined constants in C?

 
 
Keith Thompson
Guest
Posts: n/a
 
      12-28-2010
Ian Collins <(E-Mail Removed)> writes:
> On 12/27/10 11:00 AM, J.W wrote:
>> I am trying to compare to a defined constants in C, and I have simplified my program to the following..
>>
>> #include "stdio.h"
>> #include "stdlib.h"
>> #define INVALID_VALUE -999;
>>
>> int main(int argc, const char* argv[])
>> {
>> int test=0;
>> if(test==INVALID_VALUE) //The error line..
>> return INVALID_VALUE;
>> return 0;
>> };
>>
>> And when I use gcc to compile. it gives out error "error: expected
>> ) before ; token" Any reason that this cannot be
>> done.

>
> Just make it a const:
>
> const int INVALID_VALUE = -999;


That's ok in this case, but it means INVALID_VALUE won't be a constant
expression; for example, you couldn't use it in a case label.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
static constants are not local to the file they're defined. Luca Cerone C++ 4 03-02-2012 10:42 AM
Where are Tkinter event.type constants defined? Noah Python 1 05-05-2008 01:06 PM
constants defined in Kernel are also defined in Object? Paul Brannan Ruby 13 03-04-2008 03:09 PM
for language experts: Constants defined in an entity visible in all deeper inner entities albert.neu@gmail.com VHDL 7 05-09-2006 02:43 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM



Advertisments