Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

RE: [AVR-Chat] Re: Mixing gcc C & C++

2012-12-06 by Chuck Hackett

Thanks to all for the guidance on mixing gcc C & C++.  I tried converting
one of the modules within my current project and the first thing I ran into
was the fact that I had:

typedef uint8_t bool;

and C++ did not like me trying to redefine his "bool" symbol :-)  ... easily
fixed ...

Then I received the following error:

Relay.cpp|297|warning: only initialized variables can be placed into program
memory area

On the following line of code (the actual statement was buried within a
"trace" macro I use but this duplicates the error):

printf_P( PSTR( "xyz" ) ) 

After expanding the PSTR macro, it results in:

printf_P( ((const PROGMEM char  *)("XYZ")) )

Isn't PSTR creating an initialized variable?

Do I have to break this statement into two statements: one declaring the
variable and one using the variable?  If so, since this is inside a "trace"
macro how do I automatically generate unique variable names?

Obviously, all this is to prevent all trace format strings (there are a lot
of them) from consuming valuable SRAM.

For reference, the full macro is:

//
//	Trace formatter
//
//	Note: The "##" below is required so that the compiler will accept
//			"RelayBoard_Trace( fmt )" i.e.: no args after "fmt"
//
#if !defined( RelayBoard_Trace_Level )
#	error RelayBoard_Trace_Level is not defined
#endif
#if RelayBoard_Trace_Level != TL_None
#define RelayBoard_Trace_P( Level, format, ... ) \
	if (Level <= RelayBoard_Trace_Level) \
		printf_P( PSTR( format ), ##__VA_ARGS__ ) \
	else \
		;		
#else
#define RelayBoard_Trace_P( Level, format, ... ) /* Trace is turned off */
#endif
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.