Quote:
|
Originally Posted by deltacoder1020
never put the keyword "extern" in a header file - the whole point of extern is that it points to a variable declared in another file. If you put the "extern"-ed variable declaration in the header file, you'll either have two definitions of the variable, or no definition without "extern" (you always have to have one without extern).
just put "extern" variable declarations at the beginning of an individual file.
|
He already declared counter in user_routines.c. If he puts an "extern" declaration in the header file, the variable will become static (extern is a type of statically declared variable), and able to be referenced by any file that includes "user_routines.h" (including user_routines.c). This is the way I typically declare a global var since my team has 10 programmers (6 students and 4 mentors) and every student has thier own .c file to work on.
Back on topic:
Code:
unsigned long longvar = 0xFAAABBBB;
unsigned int shortvar = 0;
shortvar = longvar;
You will get an overflow error with this code. You need to right shift out the 16 least significant bits of longvar and assign shortvar to the 16 most significant bits as shown here:
Code:
shortvar = (unsigned int)(longvar >> 16);