Hello Friends,
This seems to be trivial but bugging me a lot. I am trying to create a header file with following statements:
Char BinaryCMD[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x06};
int temp calcCRC16(6, BinaryCMD);
array[6] = temp >> 8;
array[7] = temp;
calcCRC16 calculates 16-bit CRC and takes number of bytes and a pointer to the array as its arguments.
First two lines are ok in the code; however, 3rd and 4th lines cause compiler to fail. If I place this entire code in a function – say main() – it works ok. But anywhere outside a function, it fails. How can I solve this problem?
Thanks
|
Ambitious contributor
|
|
| 2Feb2008,23:37 | #2 |
|
Put it inside main.
C has no concept of having executable code outside of functions. C++ can do it, but that's only for constructing global objects. |
|
Newbie Member
|
|
| 3Feb2008,00:01 | #3 |
|
Quote:
Originally Posted by Salem Thanks, |
|
Ambitious contributor
|
|
| 3Feb2008,01:29 | #4 |
|
Why is doing it once at the start of main such a big issue to you?
|
|
Newbie Member
|
|
| 3Feb2008,03:39 | #5 |
|
Quote:
Originally Posted by Salem |
|
Ambitious contributor
|
|
| 3Feb2008,12:52 | #6 |
|
So create a function called 'initGlobalVariables' which is called right at the start of main.
|
