'1u' not accepted while gcc does

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

'1u' not accepted while gcc does

Post by cborn »

Hello, i tried an example on wiki and with gcc it just works but zcc gives a big error
it seems to fail on ' 1u ' a part of the line:
putchar(x & (1u << i) ? '1' : '0');

do i need another lib ??
https://en.wikipedia.org/wiki/Bitwise_o ... ator_usage
is it realy C and not a derivate ??

btw i included
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

result gcc:

Code: Select all

chris@cb:~/Desktop/try-C/c_in_zx/sysvars$ gcc showbits.c -o showbits -Wall
chris@cb:~/Desktop/try-C/c_in_zx/sysvars$ ./showbits
5225 in binary 		 00000000000000000001010001101001
5225 right shift 0 gives 00000000000000000001010001101001
5225 right shift 1 gives 00000000000000000000101000110100
5225 right shift 2 gives 00000000000000000000010100011010
5225 right shift 3 gives 00000000000000000000001010001101
5225 right shift 4 gives 00000000000000000000000101000110
5225 right shift 5 gives 00000000000000000000000010100011
result zcc:

Code: Select all

chris@cb:~/Desktop/try-C/c_in_zx/sysvars$ zcc +zx -v showbits.c -o showbits -lndos -create-app -lm

PROCESSING showbits.c
z88dk-ucpp -iquote"." -D__Z88DK -D__SPECTRUM -DSPECTRUM -D__SPECTRUM__ -D__Z80 -DZ80  -DSCCZ80 -DSMALL_C -D__SCCZ80 -isystem"/home/chris/z88dk/lib/config/../..//include"    "showbits.c" "/tmp/tmpXX3BuTmQ.i2"
z88dk-zpragma -sccz80 -zcc-opt=/tmp/tmpzccXXojODKG/zcc_opt.def < "/tmp/tmpXX3BuTmQ.i2" > "/tmp/tmpXX3BuTmQ.i"
sccz80  -ext=opt -mz80 -zcc-opt=/tmp/tmpzccXXojODKG/zcc_opt.def -standard-escape-chars   "/tmp/tmpXX3BuTmQ.i" -o "/tmp/tmpXX3BuTmQ.opt"
showbits.c:9:30: error: Missing token, expecting ) got u
showbits.c:9:30: fatal error: Too few arguments to call to function 'fputc_callee'
Compilation aborted
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: '1u' not accepted while gcc does

Post by cborn »

SOLVED::

it has to be a Capital U in zcc !!
wrong: putchar( x & ( 1u << i ) ? '1' : '0') ;

correct: putchar( x & ( 1U << i ) ? '1' : '0') ;

what a slight difference
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: '1u' not accepted while gcc does

Post by cborn »

Hello
and wat about
%hhu ??

Code: Select all


#include <stdio.h>
int main() {
    unsigned char a = 0, b = 0, c = 0;
    scanf("%hhu", &a);
    printf("a = %hhu, b = %hhu, c = %hhu\n", a, b, c);
    scanf("%hhu", &b);
    printf("a = %hhu, b = %hhu, c = %hhu\n", a, b, c);
    scanf("%hhu", &c);
    printf("a = %hhu, b = %hhu, c = %hhu\n", a, b, c);
    return 0;
}
https://stackoverflow.com/questions/458 ... for-printf

if i see it correct %hhu is c99 , what reference has zcc to this ??? or is zcc plain C ? 99 the YEAR ??
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: '1u' not accepted while gcc does

Post by dom »

The lower case size modifiers were fixed in this issue: https://github.com/z88dk/z88dk/issues/1623 last year.

Yes, it looks like %hh processing is missing, I can add it with probably only a cost of 10-20 bytes or so. However it's really not need since for the call to printf, sizeof(char) == sizeof(short) == sizeof(int), that is everything smaller is promoted to a 16 bit integer.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: '1u' not accepted while gcc does

Post by dom »

dom wrote: Mon Apr 12, 2021 7:45 amYes, it looks like %hh processing is missing, I can add it with probably only a cost of 10-20 bytes or so. However it's really not need since for the call to printf, sizeof(char) == sizeof(short) == sizeof(int), that is everything smaller is promoted to a 16 bit integer.
It took 8 bytes in the end. The nightly or 2021-04-13 will have it in.
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: '1u' not accepted while gcc does

Post by cborn »

THANK YOU !!!
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: '1u' not accepted while gcc does

Post by cborn »

it works now!
Post Reply