AW: [Icc-avr] Error message

Daub, Stephan stephan.daub at sap.com
Wed Sep 5 06:01:59 PDT 2007


Hi Derek,
 
>but force the correct scope, 
yes,
 
>or am I still not getting this?
no :)
 
<start of blahblah>
Defining/getting the correct scope (of attributes/funcs) is key for maintainability/robustness.
Because there is no other (higher) control instance available (as is in JAVA, C#),
you have to do this by your own in C and partly (in C++).

And because I want to avoid unmaintainable spaghetti code && unstructured use of EXTERN && useless use of globals 
also (yes, for a little cost for getter()/setter()) I prefer strict using of <module>.h/.c paires that contains
everything of this "class/module-like" thing. (of course || yes, this does not make standard-C "OO", but it 
help to reuse and organize my stuff.

Simple example: I have encapsulated all stuff for my own standard "packages" (example: my own (LIN like) protocol, 
motor drivers, task hanlder, eeprom access,...) in that way, and never had a problem to reuse this "classes" within 
other projects; better: this reduce my project startup time by far, and I do not care about 
the right scope of 'foo()' or 'extern char _baa' anymore. 
It's now <module>foo() (with the <module>.h at right place) and <module>g/set_baa() - done.

But: Yes: I partly intend to break this rule for (non-complex || easy to maintain || 
mini projects || super timecritical), esp. with the non-existance of tons of flash... 
because the above policy blow up code by some percent. 
But it's my impression that a code effectiveness review helped me to find an 
equivalent amount of flash- so: for me it's a win/win anyway.

But2: I am sure that this is a very common thing for the participants of this digest...:)

	this is why: <end blahblah>; back to work now...:)

HTH&Best 
Stephan


________________________________

Von: icc-avr-bounces at imagecraft.com [mailto:icc-avr-bounces at imagecraft.com] Im Auftrag von Robertson, Derek
Gesendet: Dienstag, 4. September 2007 11:47
An: Discussion list for ICCAVR and ICCtiny Users. You do NOT needtosubscribeto icc-announce if you are a member of this.
Betreff: RE: [Icc-avr] Error message


Ah... I get it...
 
It's like a "Only do this once" flag to the compiler.
 
So, first time round __AABB_H__ isn't defined, so define it and do <something>.  The next time the header is 'called',  the compiler gets to this bit, __AABB_H__  has been defined so you skip <something>.
 
I've seen this construct a lot, but hadn't really understood it or questioned it.
 
So you could do something like....
 
#ifndef  INIT
  #define INIT //
  unsigned char myVar = 0;
#endif
 
void Set_myVar(unsigned char); 
unsigned char Get_myVar(void);
 
Then by including the header in several C files you make the function proto-types 'public', but myVar only get's declared and initialised once.  Would I be right in saying that you would need to compile the the C file to Object before compiling your project for myVar to be private to the correct module?
 
 
Would doing this in your C file
 
#define C_FILE_NAME
 
and this in your header file
 
#ifdef  C_FILE_NAME
  unsigned char myVar = 0;
#endif
 
void Set_myVar(unsigned char); 
unsigned char Get_myVar(void);
 
Not achieve the same result but force the correct scope, or am I still not getting this?
 
Derek
________________________________

From: Daub, Stephan [mailto:stephan.daub at sap.com] 
Sent: 04 September 2007 09:57
To: Discussion list for ICCAVR and ICCtiny Users. You do NOT needtosubscribeto icc-announce if you are a member of this.
Subject: AW: [Icc-avr] Error message


Hi Derek,
 
this 
 
  #idndef __AABB_H__     /* Avoids multiple inclusion */ 
  #define __AABB_H__  
        <something>
  #endif     /* end of  #ifndef __AABB_H__ , at end of file */
 
construct is to avoid more than one execution of <something> if this .h file is included in more than one .c file....
I think it's a standard K&R C recommendation....
I re-use a standard template for .h files which include such a contruct; this is to help-and-use-but-not-worry-anymore on your .h files.
 
 
@Ton: I like your approach very much; I always try to organize my projects in that way.
IMHO and not 100% serious: if many more people had followed that way (instead of C-spaghetti code) the OO-hype won't be there ;)
 
Best, Stephan

________________________________

Von: icc-avr-bounces at imagecraft.com [mailto:icc-avr-bounces at imagecraft.com] Im Auftrag von Robertson, Derek
Gesendet: Dienstag, 4. September 2007 10:13
An: Discussion list for ICCAVR and ICCtiny Users. You do NOT needtosubscribeto icc-announce if you are a member of this.
Betreff: RE: [Icc-avr] Error message


 
Presumably the myCar, myVar in this post is a typing error?
 
Ton, I get your 'Object' approach, but I don't understand what this is for
 
    #idndef __AABB_H__     /* Avoids multiple inclusion */ 
    #define __AABB_H__  
 
I feel there may be a moment of enlightenment coming on! :o)
________________________________

From: Jaspers, Ton [mailto:t.jaspers at cpseurope.com] 
Sent: 04 September 2007 08:40
To: benra at imt.liu.se; Discussion list for ICCAVR and ICCtiny Users. You do NOT need to subscribeto icc-announce if you are a member of this.
Subject: RE: [Icc-avr] Error message


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

 
________________________________

Logitech Ltd is a limited company registered in Scotland. Registration Number: SC42330 
Registered Address: Erskine Ferry Road, Old Kilpatrick, Glasgow, G60 5EU, Scotland, UK 
________________________________

 
This message (and any associated files) is intended only for the use of the individual or entity 
to which it is addressed and may contain information that is confidential, subject to copyright 
or constitutes a trade secret. If you are not the intended recipient you are hereby notified that 
any dissemination, copying or distribution of this message, or files associated with this message, 
is prohibited. If you have received this message in error, please notify us immediately by replying 
to the message and deleting it from your computer. 
Messages sent to and from us may be monitored. 

Any views or opinions presented are solely those of the author and do not necessarily represent 
those of the company. 



More information about the Icc-avr mailing list