Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I think
strlen
is called tons of times.Merged, thanks!
fork
In C, failure message is not helpful.
Fixed
Merged, thanks!
Thank you both for the detailed explanation!
What I like about
ctype
functions acceptingint
is that it's not possible to make them accept Unicode code points without breaking compliance because despite of acceptingint
, the value still has to be representable with 8 bits.Hobovsky is right; the Linux manpage for
ctype.h
functions gives more details:I think the reason behind this might be purely historical: these functions were implemented as O(1) lookup tables indexed by the value of
c
. This worked well for 7-bit ASCII, but if a negative value is passed this would access the lookup table out-of-bounds.The negative
char
s are not a remote possibility either: this will happen if you use modern UTF-8 encoded strings on a platform wherechar
is signed (which is pretty much all of them by default).The
<ctype.h>
functions are problematic for several reasons: they depend on the locale, they are inadapted to modern Unicode where "characters" span more than one byte, theis___()
predicates do not return abool
, the cast to(unsigned char)
is necessary if one wants to write clean code. But I use them on Codewars because I like to use builtins and I know that on Codewars they will always work the way I expect them to.That's because
cctype
functions do not work well with characters represented with negative values.cctype
functions acceptint
equivalent of one character as parameter, and if on a given platformchar
is signed, then characters above0x7F
end up being passed as a negativeint
, which might be not what such function expects.It makes sense, because
\
is misleading when presented in assertion messages.Why casting to unsigned char?
Removing
\
from tests?Reopen scarecrw's issue below, since the JavaScript version still tests non-existing frets.
.
Loading more items...