[Icc-avr] Error message

Jaspers, Ton t.jaspers at cpseurope.com
Tue Sep 4 00:40:16 PDT 2007


Close but I rather use this:
 
    In main file:
    unsigned char myVar=0;
 
    In other files:
    extern unsigned char myCar ;    /* no initialisation, it is initialised where it ios defined only */

 
Further more I would suggest to put the external in a header file. 
If the declaration is in "aabb.c" then put the external in "aabb.h"  like this:
 
    #idndef __AABB_H__     /* Avoids multiple inclusion */ 
    #define __AABB_H__   
 
    extern unsigned char myCar ;
 
 
    #endif     /* end of  #ifndef __AABB_H__ , at end of file */
 
 
Personally I hate externals. I like to think in objects. 
The aabb.c file should provide an access methode (function) to access the  myCar variable. 
In the "aabb.h" header file it would like something like this:
 
    #idndef __AABB_H__     /* Avoids multiple inclusion */
    #define __AABB_H__    
 
 
    unsigned char readMyCar(void) ;
    int writeMyCar(unsigned char); 

    #endif     /* end of  #ifndef __AABB_H__ , at end of file */
 
These access methodes provide a well controlled way to access the variable. 
The write functions, for example, could perform some range checking and return an error when the value is out of range. 
This is how we do it in medical instrument software that has to be scrutenized to the bone.  
 
 
Cheers, Ton
 


________________________________

	From: icc-avr-bounces at imagecraft.com [mailto:icc-avr-bounces at imagecraft.com] On Behalf Of Bengt Ragnemalm
	Sent: dinsdag 4 september 2007 9:08
	To: ICC-AVR discussion list
	Subject: SV: [Icc-avr] Error message
	
	

	Sorry, sorry SORRY, I missed the very important word extern in one of the lines! The static should not be there either. Here is how it should be:

	 

	In main file:
	unsigned char myVar=0;
	 
	In other files:
	extern unsigned char myCar=0;

	 

	Now you can see that the problem is that I have put a predefined value in the second line.

	 

	/Bengt

	
	
	

	 

	
________________________________


	Från: John Baraclough [mailto:j_baraclough at zetnet.co.uk] 
	Skickat: den 3 september 2007 18:32
	Till: benra at imt.liu.se; Discussion list for ICCAVR and ICCtiny Users. You do NOT need to subscribe to icc-announce if you are a member of this.
	Ämne: Re: [Icc-avr] Error message

	 

	Hi Bengt,
	
	You got that message because that is exactly what you have done. Global variables can only be defined in one place in the whole project. Everywhere else you must use the 'extern' keyword.
	
	John
	
	
	P.S. Last week Richard said he was going away for a "couple of years". I hope he only meant a "couple of weeks", but he has been very quiet.
	
	
	At 07:50 03/09/2007, you wrote:
	
	

	I got this error:
	 
	!E filename.o(294): multiple define: 'myVar
	 
	I did have some problems with multiple defined variables because of a bad #define in a header. But it was not with this variable so I just didn't understand a thing until I found out that I had assigned a value to this global variable and also by mistake assigned it in the place there it was defined as extern. Like this:
	 
	In main file:
	static unsigned char myVar=0;
	 
	In other files:
	unsigned char myCar=0;
	 
	Richard: Is it possible that this could result in some other error message than "multiple define"? Something like "multiple assigning of predefined value..."
	 
	/Bengt
	________________________________________________________________
	
	Bengt Ragnemalm                         Tel +46 13 22 24 97
	
	Research engineer                                       FAX: +46 13 10 19 02
	
	Linköpings Universitet                                mailto:bengt.ragnemalm at imt.liu.se
	
	Inst. för Medicinsk Teknik Internet:        http://www.imt.liu.se <http://www.imt.liu.se/> 
	
	S-581 85 Linköping SWEDEN
	
	 
	 
	_______________________________________________
	Icc-avr mailing list
	Icc-avr at imagecraft.com
	http://dragonsgate.net/mailman/listinfo/icc-avr

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20070904/0da5b359/attachment-0001.html


More information about the Icc-avr mailing list