B
Blue Ocean
I am definitely a C newbie, and I'm having some difficulty making a
structure. I must be missing something (or the manual I'm looking at
is missing something), but I can't figure out what.
Oh yeah, this is -not- for class of any kind, just my own curiosity.
My school does not begin teaching C or C++ until middle of sophmore
year on the CS track, so I'm trying to learn a little of my own on the
side.
struct registers
{
int bankSize;
int *progCounter;
int *instRegister;
int contents[REGISTERS];
/* contents[0] = 0;
*progCounter = &contents[0];
*instRegister = contents[1];*/
};
The commented part will not compile on my machine. In fact, none of
those three lines will compile. My sense of logic tells me that this
means that I cannot actually initialize variables in structures, but I
do not know how else I should initialize them; they will always be
what they are there. Do I create a function to do it for me and
return the new structure?
Another question. The manual that I was reading said that there was a
rule of thumb that semicolons never went to the right of a curly
brace. Nonetheless, a semicolon there is and the compiler seems to
have no trouble with it.
Does anyone have a link to a place that explains the preprocessor
directives well? I've read several versions of different FAQs and
online instructional pages and I still haven't really got a handle on
them.
Thanks anyone for any help in advance. Also, if I've messed up some
forum rule or anything, please tell me, since I'll need to know when I
have a new problem.
James
structure. I must be missing something (or the manual I'm looking at
is missing something), but I can't figure out what.
Oh yeah, this is -not- for class of any kind, just my own curiosity.
My school does not begin teaching C or C++ until middle of sophmore
year on the CS track, so I'm trying to learn a little of my own on the
side.
struct registers
{
int bankSize;
int *progCounter;
int *instRegister;
int contents[REGISTERS];
/* contents[0] = 0;
*progCounter = &contents[0];
*instRegister = contents[1];*/
};
The commented part will not compile on my machine. In fact, none of
those three lines will compile. My sense of logic tells me that this
means that I cannot actually initialize variables in structures, but I
do not know how else I should initialize them; they will always be
what they are there. Do I create a function to do it for me and
return the new structure?
Another question. The manual that I was reading said that there was a
rule of thumb that semicolons never went to the right of a curly
brace. Nonetheless, a semicolon there is and the compiler seems to
have no trouble with it.
Does anyone have a link to a place that explains the preprocessor
directives well? I've read several versions of different FAQs and
online instructional pages and I still haven't really got a handle on
them.
Thanks anyone for any help in advance. Also, if I've messed up some
forum rule or anything, please tell me, since I'll need to know when I
have a new problem.
James