tags:

views:

173

answers:

4

Is there any way you do something like...

#define {  { printf("%s,%s",_FUNCTION_, _LINE_); { 

this won't compile. But I'm wondering if there is some kind of trick to effectively get the same functionality? (other than writing a tool to hook at the preprocessing step)

The point of doing this is a pondering on how to get a poor mans code coverage.

+6  A: 

It's certainly not possible with a macro. The name of a macro must be an identifier. The brace characters are punctuators, not identifiers.

James McNellis
sorry, edited the question, I know its not possible with macros as is.... was looking to see if there's a trick, or even a non standard compiler trick
Keith Nicholas
@Keith: A trick to change the way brace punctuators are handled? I doubt it; that's a rather unusual "feature request" :-).
James McNellis
@James, I know..... I know.... but how cool would that be :-) It's C after all, give me the power to Nuke myself in the head :-)
Keith Nicholas
+1  A: 

I've seen this done (not that I endorse it...) with #define BEGIN ... and #define END ....

e.g.

void foo(void)
BEGIN
    stuff();
END
bstpierre
really don't want that, would like to be able to adhoc change the { and } to something else, as someone said, poor mans AOP to get poor mans code coverage
Keith Nicholas
A: 

You can't change the way the compiler interprets {}'s. It's an assumption that they make to be able to syntaxically determine if the code is correct and what it is supposed to do.

If you indeed would like to do something like that, I suggest doing a search-and-replace on "{" "{ MY_MACRO;"

Simon
+1  A: 

Get rich-man's code coverage with the tools discussed in these questions, particularly gcov, which is part of GCC.

Ken Bloom
yes, I realize I could use a rich tool, but I was also going to inject debug code for an embedded system so you could trace what its doing. Sort of a real time coverage system....
Keith Nicholas