nedoPC.org

Electronics hobbyists community established in 2002
Atom Feed | View unanswered posts | View active topics It is currently 19 Mar 2024 02:58



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

Joined: 08 Jan 2003 23:22
Posts: 22383
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);
   

_________________
:dj: https://mastodon.social/@Shaos


06 Nov 2004 21:37
Profile WWW
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22383
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

_________________
:dj: https://mastodon.social/@Shaos


21 Dec 2020 21: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 4 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.