Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,485 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Preprocessor... #384088
09/29/11 02:33
09/29/11 02:33
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline OP
User
Gordon  Offline OP
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
In the current preprocessor the line is evaluated for keywords before the macros are evaluated. Macros need to be fully expanded before any keyword processing.

The reasoning for this is that keywords can be redefined to include instrumentation statements that can then be removed by not defining the macro.

The other option for this is to allow for a real preprocessor to be run from SED on compile click and pass the resulting code to lite-c.


Our new web site:Westmarch Studios
Re: Preprocessor... [Re: Gordon] #384101
09/29/11 10:33
09/29/11 10:33
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Can you give an example?

Re: Preprocessor... [Re: jcl] #384122
09/29/11 14:32
09/29/11 14:32
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline OP
User
Gordon  Offline OP
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
Code:
#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.

Our new web site:Westmarch Studios
Re: Preprocessor... [Re: Gordon] #384127
09/29/11 16:27
09/29/11 16:27
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I see now at least what you meant. No, macros are evaluated by the preprocessor, and keywords are evaluated by the compiler. All C languages behave this way.

Your example won't work because lite-C macros expect expressions as arguments, and "; i < 100; i++" is no valid expression. The lite-C preprocessor is a little simpler than a C++ preprocessor.

Re: Preprocessor... [Re: jcl] #384129
09/29/11 16:35
09/29/11 16:35
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
From memory, SOMETHING like this would work though, am I right?

Code:
#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: EvilSOB] #384130
09/29/11 16:36
09/29/11 16:36
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
No, the macro itself is ok, it's just called with a wrong parameter. {..} won't help in this case.

Re: Preprocessor... [Re: jcl] #384168
09/30/11 04:18
09/30/11 04:18
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline OP
User
Gordon  Offline OP
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
Just tried it with visual studio express... it does work.

try it yourself

Code:
// 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
Code:
#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);
	}
}




Our new web site:Westmarch Studios
Re: Preprocessor... [Re: Gordon] #384175
09/30/11 08:13
09/30/11 08:13
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Which part of the response have you not understood?

Re: Preprocessor... [Re: jcl] #384182
09/30/11 11:34
09/30/11 11:34
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline OP
User
Gordon  Offline OP
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
The part where lite-c does not even try to expand the macro. If you look at it it will compile without errors even though there is an obvious error in the expansion text of the macro. And the fact that visual studio will compile and run an equivalent program with no errors or warnings. The preprocessor should only be looking for "," and ")" while parsing the input text of the macro and will not care about the ";". The preprocessor in lite-c should work at least as good as the one for the old cp/m OS called small-c.


Our new web site:Westmarch Studios
Re: Preprocessor... [Re: Gordon] #384201
09/30/11 14:41
09/30/11 14:41
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Improved macro preprocessing is certainly nice to have, but not planned at the moment - other language features have higher priority.

Page 1 of 2 1 2

Moderated by  jcl, Nems, Spirit, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1