It is currently Mon Nov 12, 2018 11:42 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: I mean, WTF...
PostPosted: Fri Nov 14, 2008 3:28 pm 
Offline

Joined: Thu Sep 15, 2005 9:23 am
Posts: 1194
Location: Behind you with a knife!
Code:
if (CPU.A16 < 0x10)
   sprintf(Output, "A: 0x000%X", CPU.A16);

...won't work but...

Code:
if (CPU.A16 < 0x10)
   sprintf(Output, "A: 0x0%X", CPU.A16);


...just because I remove those two 0's. It puts the correct data into Output, but TextOut just returns 'The paramenter is incorrect.'.

I mean, WTF?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2008 3:34 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20760
Location: NE Indiana, USA (NTSC)
How big is Output?

And what are you doing when A16 >= 0x10? I have a feeling what you're trying to do in the sprintf has something to do with 0x%02X or 0x%04X.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2008 3:37 pm 
Offline

Joined: Thu Sep 15, 2005 9:23 am
Posts: 1194
Location: Behind you with a knife!
Well I changed char *Output = ""; to char Output[100]; and now it works. Thanks anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 15, 2008 6:49 am 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Attempting to write to a string literal is undefined behavior. Doesn't your compiler warn when you try to assign a string literal to a non-const char pointer? By being const-correct, the compiler can diagnose the error for you:
Code:
char* p = "foo"; // error in C++, and C compiler should warn
*p = 'b'; // will compile, but cause UB when executed
sprintf( p, "bar" ); // same, causes UB

const char* cp = "foo"; // OK
*cp = 'b'; // error because cp points to const object
sprintf( cp, "bar" ); // error because sprintf expects pointer to non-const char


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group