Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
gregd99
PostPosted: Jul 28, 2012 - 09:37 AM
Hangaround


Joined: Oct 10, 2011
Posts: 237
Location: Sydney, Australia

As a learning experience I have been converting some parts of existing C code to CPP for an atmega16.

I started with AS5.1 and had the application working. I have now moved to AS6 and have a set of issues with the same code:-(

One of the problems is some confusion with methoid signatures.

The first method below calls a putstr routine where the string is in flash; the second where it is in ram.

Code:
void debugQ::putstr( const char *str)
{
   putstr_debug_P(str);
}
void debugQ::putstr( char *str)
{
   putstr_debug(str);
}


in AS51. this worked well.... the "const" qualifier differentiated between the two methods. in AS6 the first method is always called. as you can imagine this does not work well when the string is in ram....

has anyone had a similar experience?

Are there any suggestions?

Thanks.

_________________
regards
Greg
 
 View user's profile Send private message  
Reply with quote Back to top
ChaunceyGardiner
PostPosted: Jul 28, 2012 - 11:09 AM
Posting Freak


Joined: Mar 09, 2012
Posts: 1452
Location: North Carolina, USA

That's lousy design anyway - neither of them modifies str, so they should both take const parameters.

_________________
Sid

Life... is a state of mind
 
 View user's profile Send private message  
Reply with quote Back to top
gregd99
PostPosted: Jul 28, 2012 - 11:17 AM
Hangaround


Joined: Oct 10, 2011
Posts: 237
Location: Sydney, Australia

That was not a helpful response.

_________________
regards
Greg
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Jul 28, 2012 - 04:12 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18520
Location: Lund, Sweden

This seems to be a bug. AFAIK (gotta read up on it in the standard, or perhaps Stroustrup to be sure...) the "cv-qualifiers" are part of a member function signature.

Advice: Build using both AS51 and AS6. Take steps to get as much build output detail as possible. Study the differences in the two builds to see if there is some option/switch etc that differs. Dig from there..

Also, looking in the GCC bug tracker might reveal something.

You might get more help from the compiler gurus here if you report what versions of the tool chain behaves correctly or incorrectly.

Apart from that, and helpful or not, I tend to agree with Mr Gardiner on the design issue.. Wink
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
sternst
PostPosted: Jul 28, 2012 - 04:22 PM
Raving lunatic


Joined: Jul 23, 2001
Posts: 2437
Location: Osnabrueck, Germany

Quote:
in AS6 the first method is always called. as you can imagine this does not work well when the string is in ram....
Exactly how have you tested it? "in ram" does not necessarily mean "not const".
E.g. with
Code:
putstr("Hello world!");
of course the first method is called, because a string literal is a "const char *".

Quote:
Apart from that, and helpful or not, I tend to agree with Mr Gardiner on the design issue..
+1

_________________
Stefan Ernst
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jul 28, 2012 - 04:28 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62220
Location: (using avr-gcc in) Finchingfield, Essex, England

Presumably you can always cast the parameter to reach the implementation you want?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
skeeve
PostPosted: Jul 28, 2012 - 07:04 PM
Raving lunatic


Joined: Oct 29, 2006
Posts: 2640


gregd99 wrote:
As a learning experience I have been converting some parts of existing C code to CPP for an atmega16.

I started with AS5.1 and had the application working. I have now moved to AS6 and have a set of issues with the same code:-(
My suspicion is that the AS5.1 C++ compiler did it wrong and the AS6 C++ compiler is doing it right.
Quote:
One of the problems is some confusion with methoid signatures.

The first method below calls a putstr routine where the string is in flash; the second where it is in ram.

Code:
void debugQ::putstr( const char *str)
{
   putstr_debug_P(str);
}
void debugQ::putstr( char *str)
{
   putstr_debug(str);
}


in AS51. this worked well.... the "const" qualifier differentiated between the two methods. in AS6 the first method is always called. as you can imagine this does not work well when the string is in ram....
Are you testing with string literals?
The type of "literal" is const char[8], which converts to const char * .

Traditionally, _P has been used to mark functions that use program memory.

_________________
Michael Hennebry
Iluvatar is the better part of Valar.
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Jul 28, 2012 - 07:09 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18520
Location: Lund, Sweden

Since three wise men posted after me, I actually re-read your code. My previous response was made in flimsy haste, it seems.

Yes, there is very little to be said about right/wrong, RAM/flash, good/bad and so on without you showing code that calls those functions.

One of my mantras here is: Post a minimal but complete test program that compiles, runs and displays the problem.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits