#1340 - Vortex - Thu Jan 16, 2003 9:08 pm
Is there any way to use assert() statements in GBA programs ?
Thanks
#1360 - tepples - Fri Jan 17, 2003 12:09 am
On the GBA, you need a special assert library because the standard C assert() writes to stdout, but the GBA doesn't have a stdout unless you've linked in a serial library.
That said, there do exist some assert libraries for GBA.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#1376 - Touchstone - Fri Jan 17, 2003 11:00 am
You could easily write your own assert macro. For instance an assert that change the color of the screen by disabling all rendering to screen and setting background palette 0 to a specific color. Something like this maybe: Code: |
#ifdef _RELEASE
#define assert(_exp, _col)
#else
#define assert(_exp, _col) if(!(_exp)) {disable rendering; set background to _col; while(1);}
#endif |
And use like this: Code: |
assert(Character.pos.x > 0, 0x7fff); // Halt game and set screen to white if character is out of bounds |
If you have some sort of text print you could ofcourse use that together with the macros __FILE__ and __LINE__ (and __FUNCTION__ if using gcc). I never use asserts myself though.
_________________
You can't beat our meat
#1384 - col - Fri Jan 17, 2003 2:10 pm
Touchstone wrote: |
I never use asserts myself though. |
Wow, what technique have you found thats better for putting a 'free' safety net into your code?
Assertions save me loads of time that would otherwise be spent wrestling with gdb or filling my code with ugly print statements and #ifdef/#endif pairs
I guess you never make design or coding errors ;-)
cheers
col
#1391 - Touchstone - Sat Jan 18, 2003 3:06 am
I usually go a round against the debugger. In combination with printf's if needed. :)
_________________
You can't beat our meat
#1647 - Paul Shirley - Tue Jan 21, 2003 12:41 am
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:42 pm; edited 1 time in total
#1649 - Touchstone - Tue Jan 21, 2003 1:45 am
Paul Shirley wrote: |
col wrote: | Touchstone wrote: | I never use asserts myself though. |
Wow, what technique have you found thats better for putting a 'free' safety net into your code?
Assertions save me loads of time that would otherwise be spent wrestling with gdb or filling my code with ugly print statements and #ifdef/#endif pairs
I guess you never make design or coding errors ;-)
col |
When employers ask for a code sample this is one of the things they're looking for. Claiming to never use them is like saying 'I'm a cowboy, don't employ me'.
I code mine to dump messages to the emulator print hook. I then repeat the message to a dedicated text driver reserved for debug info. Saved my bacon repeatedly. |
Claiming assert macros is the only way to find bugs is like saying 'I'm incompetent, don't employ me'.
_________________
You can't beat our meat
#1653 - Paul Shirley - Tue Jan 21, 2003 2:44 am
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:42 pm; edited 1 time in total
#1657 - Paul Shirley - Tue Jan 21, 2003 3:56 am
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:43 pm; edited 1 time in total
#1667 - Touchstone - Tue Jan 21, 2003 9:57 am
Paul Shirley wrote: |
Touchstone wrote: | Claiming assert macros is the only way to find bugs is like saying 'I'm incompetent, don't employ me'. |
Only one person suggested that - you. Please carry on and bury yourself further. |
Mr. Shirley,
I don't agree with you. I said I had never used assert macros but I have absolutely never ever suggested that using them is the only way to find bugs, like you are stating in the quote above. I fail to see where you got that from, could you please tell me. You also imply that it's only programmers who think they never make mistakes that doesn't use assert macros. This is not true either. Just because I don't use assert macros doesn't mean I'm not checking for bad parameters, I just don't do it with the assert macro. If using other techniques than the assert macro make me a 'cowboy' then fine but seriously, if a company only look for the usage of assert when reviewing work-samples I wouldn't want to work for that company anyways.
This reminds me of the poster with the quote "Arguing on the internet is like competing in the special olympics. Even if you win you are still a retard." Thanks for making it so obvious and for making me look like a fool.
_________________
You can't beat our meat
#1691 - col - Tue Jan 21, 2003 5:02 pm
One thing is that when there are multiple programmers working on the same code, printf's could start to cause problems - eg. finding them all to comment them out etc...
with asserts you just turn them off!
If i was choosing between two candidates for a job and the only difference in their code was that one used assertions and the other used printf instead, I know which candidate i would choose...
cheers
col.
#1692 - Touchstone - Tue Jan 21, 2003 5:52 pm
I think that most often you'd want a more graceful solution to a erroneous parameter than what the assert macro has to offer.
If you turn asserts off you'd still need to verify that your parameter is valid before using it so I figure, why not extend that verification to include whatever assert does. I think that's the reason why I've never used asserts.
If I was choosing between two candidates for a job, one of them used asserts while the other had code that could recover from errors I think I'd go for the error recoverable code-applicant.
_________________
You can't beat our meat
#1695 - Sweex - Tue Jan 21, 2003 6:21 pm
Hehe! Let's join this discussion!
I don't agree with "If you turn asserts off you'd still need to verify that your parameter is valid before using it so I figure, why not extend that verification to include whatever assert does".
No offense, but if you still verify parameters when you turn off asserts, you've missed the point of assertions IMHO.
You turn off assertions when you are doing a "release build", when you are sure your code is working correctly (and thus the parameters passed to functions are always correct)!
(btw., I'm using my own assert which outputs a nice textscreen when one fails.)
#1703 - grumpycat - Tue Jan 21, 2003 8:13 pm
I use asserts, but in my career I have seen lots of software failures due to bad asserts. Some asserts are born bad - generally when an engineer misunderstands the data structures or the API... and sometimes they're in codepaths that end up slipping through the unit testing and SQA process. The most common case I have found is that as a body of code evolves and different engineers add to it, some asserts stop being valid - an invariant becomes variable. A "this pointer will never be NULL" evolves into, "sure it can...", but the assert is dug deep in a module that has not kept pace with the progress of the rest of the system, and sooner or later it trips.
I've also seen asserts used by lazy programmers trying to seem not lazy:
Code: |
p = malloc(sizeof(foo_t));
assert(p != NULL); |
Awful.
I don't belive the "asserts are good and you suck if you don't use them" argument. That's pretty arrogant. I also wouldn't choose an engineer based on whether they used assert or not.
I would certainly never hire an engineer based on a code fragment. Sit them down and ask them to solve some problems, don't measure a candidate based on how neat and tidy and prettily indented their code is. Talk to them. How do they design? How do they debug? Do they use source control? How well do they argue a position? Are they a team player? But, "Do they use 8-space tabs and asserts?" Give me a break.
Maybe this is a contractor thing? I've never been on that side, so maybe contracting is all about code samples... but for full-time engineers, I'd walk away if I was asked for actual code.
We can get very personal about what software engineering tools and processes are best (vi vs. emacs, perl vs. python, Coke vs. Pepsi), but this isn't football, and there's more to it than "my team rules and your team sucks".
Q. Who is the better engineer: Touchstone or Paul Shirley?
I can't answer that. I won't even try.
Grumpy.
#1723 - Touchstone - Tue Jan 21, 2003 11:47 pm
Thank you Grumpy for giving your opinions on this matter. But what's more important, thank you for not taking any side but rather expressing an independent view the way you did.
I feel that what you've written is basically what I've been trying to say with my last two posts but I couldn't make myself understood correctly. I'm sure asserts are very useful but I don't think it's fair to assume that someone who doesn't use asserts is a bad programmer, there's much more to it.
_________________
You can't beat our meat
#1730 - Splam - Wed Jan 22, 2003 3:49 am
No asserts for me either ;)
I'm not going to waffle about why because it's just personal choice and coding style. I could say I know enough about what I'm doing before I start coding not to need them but then someone would tell me I was stupid :P
#3532 - mantrid - Wed Feb 26, 2003 7:13 pm
Asserts have been very useful for me when porting MME. Mine look like this:
#define UB_ASSERT(exp) (void)( (exp) || (dprintf("ASSERTION: (" #exp ") @ " __FILE__ ":%d\n", __LINE__), 0) )
#define LOG_BUFF_SIZE 2000
char log_buff[LOG_BUFF_SIZE];
static void dprint(const char *sz) {
asm volatile
(
"mov r2, %0\n"
"ldr r0, =0xc0ded00d \n"
"mov r1, #0\n"
"and r0, r0, r0\n"
: /* No output */
: "r" (sz)
: "r0", "r1", "r2"
);
}
Copied that dprint off the visualboy advance site.