[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] (no subject)

From: David Brown
Subject: Re: [avr-gcc-list] (no subject)
Date: Tue, 31 Jan 2006 10:27:41 +0100

This is exactly right.

Is there a good web page that explains this stuff, so that we don't have to
explain these C fundamentals on a regular basis?  I know I've had to do it
on the avr lists and many other compiler lists, and it gets a bit annoying
after a while - especially the invariable arguements with someone who thinks
all this "#define EXTERN_GLOBAL extern" shite is a good idea.

If people want to write embedded systems in C, they should first learn to
write C.  That means learning what "extern" means (as described below), and
how headers and source files should be divided up.  Just because C is
painfully poorly designed language and lets you write disorganised drivel,
such as declaring variables in headers, does not mean that this is sensible
code to write.



----- Original Message -----
From: developer2112 (sent by Nabble.com)
To: address@hidden
Sent: Tuesday, January 31, 2006 3:12 AM
Subject: Re: [avr-gcc-list] (no subject)

Header files aren't meant for declaring variables; it's actually against the
ANSI standard. What you need to do is put your global variables in a C file;
perhaps globals.c...then create a header file. Title the header file with
the same base name, in this case globals.h. Globals.h should look like this:

#ifndef _GLOBALS_H_  // i use _BASENAME_H_ use whatever you like
#define _GLOBALS_H_ // this prevents multiple includes

extern int nMyGlobal;
extern ...


Then in my C files:

#include "globals.h"  // this can be used in ALL files, you can even include
it in globals.c itself

nMyGlobal = 10;

If you stick to this convention, you will never have this kind of problem
again no matter what ANSI C compiler you are using. Many people don't know
it, but you can use extern even if the variable or function is in the same
module without any penalties. All it does is it tells the compiler that the
reference will be resolved at link time as opposed to compile time.

View this message in context: Re: (no subject)
Sent from the AVR - gcc forum at Nabble.com.

AVR-GCC-list mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]