nedoPC.org

Community of electronics hobbyists established in 2002
Atom Feed | View unanswered posts | View active topics It is currently 16 Sep 2021 10:29



Reply to topic  [ 2 posts ] 
Solid C: bugs.txt 
Author Message
Admin
User avatar

Joined: 09 Jan 2003 00:22
Posts: 19894
Location: Silicon Valley
Reply with quote
Code:
#include <stdio.h>
 
char buffer[4]="AAA";
//char buffer[4]={'A','A','A','A'};
 
void main()
{
    printf("0x%02X\n", *buffer);      // (1) it does not work
    printf("0x%02X\n", (char *) *buffer);   // (2) fixed variant
}
 
If array "buffer" is char array and we try to use it by pointer (1)
then compiler make wrong code without any warning. We may fix it as
wrote (2). Using of int array makes right code. For details you may
see asm-code generated by compiler. For line (1) compiler does not
generate code "ld b,0".

Comment from translator: Do not use %X with char data in printf/sprintf.
You need convert char to int before:

    int i = *buffer;
    printf("0x%02X\n", i);
   

_________________
:eugeek: https://twitter.com/Shaos1973


06 Nov 2004 22:37
Profile WWW
Admin
User avatar

Joined: 09 Jan 2003 00:22
Posts: 19894
Location: Silicon Valley
Reply with quote
In reality it's happening because Solid-C can't handle char if it's referenced in format as %X - for %X it expects to see int and nothing else

_________________
:eugeek: https://twitter.com/Shaos1973


21 Dec 2020 22:31
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 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
Designed by ST Software.