Gamestudio Links
Zorro Links
Newest Posts
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
3 registered members (AndrewAMD, Akow, degenerate_762), 1,430 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 4 1 2 3 4
Assertion macro #343215
10/04/10 14:38
10/04/10 14:38
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline OP
Expert
WretchedSid  Offline OP
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Heyho, I made this small assertion macro for one of my projects:
Code:
#define LFAssert(condition, message) if(!(condition)){error(message); sys_exit(NULL);}



Here is how I use it:
Code:
LFAssert(foopointer, "Some error message");



It compiles and runs great with the GCC (4.2) and LLVM (1.5, 1.6, 2.0) (same macro but printf() and abort() instead of error() und sys_exit()) but the Lite-C compiler refuses to accept the way I use it (A8.02)

Is there something that I miss or is this a bug?


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Assertion macro [Re: WretchedSid] #343242
10/04/10 17:36
10/04/10 17:36
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Youve missed the final ";" in your thinking...

Type-out the macro-replacement manually... and keep an eye on the red ";"
LFAssert(foopointer, "Some error message");
becomes
if(!(foopointer)){"Some error message"); sys_exit(NULL);};
You see?

I tend to "fake" this with a REALLY ugly hack like so...
Code:
#define LFAssert(con, msg) if(!(con)){error(msg); sys_exit(NULL);} var who_cares=0
//[[condition and message shortened just for display purposes...]]


which then becomes
if(!(foopointer)){"Some error message"); sys_exit(NULL);} var who_cares=0;

VERY ugly, but work MOST of the time...

Mind you, I wish there was a better way...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Assertion macro [Re: EvilSOB] #343244
10/04/10 17:58
10/04/10 17:58
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline OP
Expert
WretchedSid  Offline OP
Expert

Joined: Apr 2007
Posts: 3,751
Canada
I can't believe it... what an annoying thing -.-
Really, a ; too much shouldn't be a problem and every C compiler I know of doesn't complain about it.

Thank you very much EvilSOB!


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Assertion macro [Re: WretchedSid] #343249
10/04/10 18:26
10/04/10 18:26
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Groovy, I was just yesterday thinking about using an assert macro to make my code a bit safer, and then saw this thread today.

I would personally use a function as well to avoid the hacky stuff (and potential double-definitions of who_cares [even though who_cars could be declared globally and then re-assigned in the assertion, I guess]):
Code:
function failAssert(char *msg) {
	error(msg);
	sys_exit(NULL);
}
#define assert(con, msg) if(!(con))failAssert(msg)


Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: Assertion macro [Re: JibbSmart] #343251
10/04/10 18:36
10/04/10 18:36
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline OP
Expert
WretchedSid  Offline OP
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Okay, I found another thing, my fallback (#ifdef NDEBUG) looks like this:
Code:
#define LFAssert(condition, message) ((void) 0)



guess what, it isnt working... WHAT? Why? "Can't convert long to void"
My other fallback would be "asm ("nop");" but this also fails (feature request: Inline assembler!)
What do? D:

Edit: @JulzyMighty: I used a foo variable named "iLoveEvilSOB". I guess that no one uses a variable like this tongue
Btw, I just found a solution for my new problem... Just declare the variable again -.-

Last edited by JustSid; 10/04/10 18:40.

Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Assertion macro [Re: WretchedSid] #343253
10/04/10 19:16
10/04/10 19:16
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Quote:
Edit: @JulzyMighty: I used a foo variable named "iLoveEvilSOB". I guess that no one uses a variable like this tongue
You could be surprised how many people use a variable named "iLoveEvilSOB" laugh
Quote:
My other fallback would be "asm ("nop");" but this also fails (feature request: Inline assembler!)
++. I wonder what jcl would say.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: Assertion macro [Re: JibbSmart] #343258
10/04/10 20:02
10/04/10 20:02
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
No one loves EvilSOB, but he's happy that way...
There is just a lot of SARCARSTIC peoples on this forum,
who are jealous of my extreme intelligence and humility grin


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Assertion macro [Re: EvilSOB] #343259
10/04/10 20:04
10/04/10 20:04
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Back to serious mode now. How about this...
Code:
function failAssert(char *msg) 
{
#ifdef NDEBUG
   return;
#endif
   error(msg);
   sys_exit(NULL);
}
#define assert(con, msg) if(!(con))failAssert(msg)


Is that the idea of the assert?


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Assertion macro [Re: EvilSOB] #343260
10/04/10 20:21
10/04/10 20:21
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline OP
Expert
WretchedSid  Offline OP
Expert

Joined: Apr 2007
Posts: 3,751
Canada
I don't want this kind of assert because it isn't inlined like a #define is. Or at least it isn't inlined in the Lite-C compiler (feature request #2: inline functions).

But basically, yes, this would be the assert. Btw, I switched from the iLoveEvilSOB variable to an internal dummy variable with my own prefix.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Assertion macro [Re: WretchedSid] #343262
10/04/10 20:27
10/04/10 20:27
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
struct iLoveJustSid?

Page 1 of 4 1 2 3 4

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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