Connecting Tech Pros Worldwide Forums | Help | Site Map

Constants Help in C!

Newbie
 
Join Date: Jun 2009
Posts: 14
#1: Jun 19 '09
Please advise.

I have to write a declaration for a const variable named MAGENTA of type struct color whose members have the values 255, 0, and 255, respectively.

From the code I have this so far.

Color has the following structure:

struct color {

int red;
int green;
int blue;
constant MAGENTA = 255, 0, 255;
};


I cannot resolve the error for the line constant MAGENTA = 255, 0, 255.

Apologizes for the constant emails. I'm still working through the kinks in C.

Thanks.

Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 831
#2: Jun 19 '09

re: Constants Help in C!


Separate the structure and variable definitions.
Use braces to enclose the composite initializer.
Expand|Select|Wrap|Line Numbers
  1. struct color {
  2.    int red;
  3.    int green;
  4.    int blue;
  5. };
  6. static const struct color MAGENTA = { 255, 0, 255 };
Note: the 'static' keyword restricts the scope of the variable to a single source file. I don't know if that's what you want.
Newbie
 
Join Date: Jun 2009
Posts: 14
#3: Jun 19 '09

re: Constants Help in C!


Thanks, you've been a big help. I think that's what it is.
Reply