0 registered members (),
1,485
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Preprocessor...
[Re: jcl]
#384122
09/29/11 14:32
09/29/11 14:32
|
Joined: Aug 2003
Posts: 902 Van Buren, Ar
Gordon
OP
User
|
OP
User
Joined: Aug 2003
Posts: 902
Van Buren, Ar
|
#define for(a) diag("starting loop"); for(a,diag("loop"))
void foo(int i)
{
for( ; i < 100; i++)
{
diag("loop body");
}
}
on K&R up through latest compilers "for" would expand to diag("starting loop") for( ; i < 100; i++,diag("loop") { if __LINE__ and __FILE__ manifest constants were available as well then those could be used to find location. diag is just a quick example in real profiling it would call a short function to also output line, file and time. The log file would be post processes to calculate time spent after average time for output was subtracted. Additional examples can be found in "C/C++ software quality tools" by Mark L Murphy.
Last edited by Gordon; 09/29/11 14:33.
|
|
|
Re: Preprocessor...
[Re: jcl]
#384129
09/29/11 16:35
09/29/11 16:35
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
From memory, SOMETHING like this would work though, am I right?
#define for(a) {diag("starting loop"); for(a,diag("loop"));}
Im not sure though... it was a long time ago
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Preprocessor...
[Re: jcl]
#384168
09/30/11 04:18
09/30/11 04:18
|
Joined: Aug 2003
Posts: 902 Van Buren, Ar
Gordon
OP
User
|
OP
User
Joined: Aug 2003
Posts: 902
Van Buren, Ar
|
Just tried it with visual studio express... it does work. try it yourself
// test2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define for(a) printf("start loop\n"); for(a,printf("in loop\n"))
int _tmain(int argc, _TCHAR* argv[])
{
int i;
int y;
y= 0;
for (i=0; i < 10; i++)
{
y++;
}
return(0);
}
Now as for lite-c try this
#define for(a) diag("start for"); bad code to cause compile error if this is expanded for(a,diag("loop"))
void foo(int i)
{
int y;
y = 1;
for (i=0;i<100;i++)
{
wait(1);
}
}
|
|
|
|