[Z88dk-users] Use of const in clib

Bridge to the z88dk-users mailing list
Post Reply
obiwanjacobi
Member
Posts: 67
Joined: Tue Dec 22, 2015 7:39 am

[Z88dk-users] Use of const in clib

Post by obiwanjacobi »

I was surprised to get a warning on passing in a 'const char*' into the str(n)cmp function. Turns out that a lot of the string.h functions do not have a const declaration in places I would expect them.
Is the absence of the const keyword on purpose or...?

If I look at other C-library documentation, there I see the const at the expected places...



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I was surprised to get a warning on passing in a 'const char*' into the str(n)cmp function. Turns out that a lot of the string.h functions do not have a const declaration in places I would expect them.
Is the absence of the const keyword on purpose or...?
No, it's an oversight. Each time I go through the headers I find something that is not right. I'll make note to look at const for the next time through.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
obiwanjacobi
Member
Posts: 67
Joined: Tue Dec 22, 2015 7:39 am

Post by obiwanjacobi »

Error at file 'C:\Users\marc\AppData\Local\Temp\zcc50387.asm' line 674: symbol '_strnlen_callee' not defined
Did you forget one?

;)



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Error at file 'C:\Users\marc\AppData\Local\Temp\zcc50387.asm' line 674: symbol '_strnlen_callee' not defined
Did you forget one?
Oops :P



; size_t strnlen_callee(const char *s, size_t maxlen)

SECTION code_clib
SECTION code_string

PUBLIC _strnlen_callee

EXTERN asm_strnlen

_strnlen: <------ **** should be _strnlen_callee

pop af
pop hl
pop bc
push af

jp asm_strnlen




This is file libsrc/_DEVELOPMENT/string/c/sdcc_iy/strnlen_callee.asm and libsrc/_DEVELOPMENT/string/c/sdcc_iy/strnlen_callee.asm .

I'll commit the fix now but if you don't want to download again you can just edit those yourself and rebuild the libraries. I'll commit a const fix to string.h too while I'm at it though I'm sure there must be missing const in other headers too.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
obiwanjacobi
Member
Posts: 67
Joined: Tue Dec 22, 2015 7:39 am

Post by obiwanjacobi »

yep, that works



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Post Reply