[splint-discuss] Parse error with @ from the IAR compiler

Michael Wojcik Michael.Wojcik at MicroFocus.com
Fri Jan 19 06:54:45 PST 2007


> From: splint-discuss-bounces at cs.virginia.edu 
> [mailto:splint-discuss-bounces at cs.virginia.edu] On Behalf Of 
> Keith.Richeson at us.elster.com
> Sent: Friday, 19 January, 2007 09:12
> Subject: [splint-discuss] Parse error with @ from the IAR compiler
> 
> 
> 
> I'm working on an embedded project and we are using the IAR C compiler
for
> the 8051.  One of the extensions to the compiler is that it allows a
user
> to "locate" a variable using the @ symbol.  That is to say, if I want
to
> make sure that a variable gets allocated at location 0xFFE0 in RAM, I
can
> use the following declaration:
> 
> int myVar @ 0xFFE0;
> 
> and the compiler will understand the statement.
> 
> Of course since this is not standard C splint is not happy with the
above
> statement, and in fact a parse error is generated...

As it should be.  "@" isn't even part of the basic source character set
defined by ISO 9899; no C implementation is required to translate a
source file containing it.

>  My first idea of how to deal with this is to define @ = ";
> //" so that the line effectively ends at the @ symbol and everything
else
> is a comment.

I'll note in passing that prior to C99, "//" wasn't a part of standard C
either.

The real problem, though, is that "@", not being part of the source
character set, can't be used in an identifier, either, and macro names
are identifiers.

> Does anyone have any other suggestions for getting around this
> issue?

I'd wrap the compiler's special syntax in a macro, then
conditionally-compile it for Splint:

	#if defined S_SPLINT_S
		#define VAR_AT(addr)
	#else
		#define VAR_AT(addr) @ addr
	#endif

and then in your code, replace all

	int myVar @ 0xFFE0;

with

	int myVar VAR_AT(0xFFE0);

Of course, that may be more work than what you want to do.  Another
alternative would be to stick a filter into your toolchain in front of
Splint that removes all the @-expressions; that's pretty trivial if
they're all consistently formatted with the address on the same line as
the operator.  With sed, for example:

	sed "s/@[^,;]*//g" source.c > source-tmp.c
	splint source-tmp.c

Details depend on what tools you have available, but this this is easy
to do on Unix, and pretty easy on Windows with the addition of some free
software.

-- 
Michael Wojcik                517 676-0892
Software Systems Developer    Micro Focus     http://www.microfocus.com/



More information about the splint-discuss mailing list