Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: isspace() executes without ctype header? Date: Wed, 14 Jun 2017 09:35:00 -0700 Organization: None to speak of Lines: 64 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="96bbf95725af2559ab0735ee54475e20"; logging-data="28600"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MsEhHl53Smte1ExgiRP6Y" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:2CaIWUvqI4wNhElUstmnLv6fa3w= sha1:5rOPmOy8cmH90wSYgrO1UM+6mGE= Xref: csiph.com comp.lang.c:112198 bartc writes: > On 14/06/2017 02:13, DFS wrote: >> Seems strange, but the code compiles (Tiny C on Windows) and runs just >> fine with only stdio.h and stdlib.h includes. >> >> Online resources say ctype.h is the required header (which I didn't know >> obviously). >> >> I compiled the program with Pelles and got warnings: >> >> Undeclared function 'isspace' (did you mean 'vsscanf'?); assuming >> 'extern' returning 'int'. >> >> >> Why is it working without ctype.h? > > > Try this compiler** (choose either -32 or -64 version depending on your > Tiny C): > > https://github.com/bartg/langs/blob/master/bccproj/mcc32.c > https://github.com/bartg/langs/blob/master/bccproj/mcc64.c > > Use tcc to compile it, eg: > > tcc mcc32.c -omcc.exe > > Then run as: > > mcc program.c > > You won't be able to run the result (as it needs extra bits and pieces, > code is only for x64 etc), but can give a second opinion on code that > apparently passes error-free with other compilers. Why would a second opinion be needed? The standard is clear. Under C90, calls to undeclared functions are permitted. Under C99 and C11, they're a constraint violation. and do not declare isspace(); does. This: #include #include int main(void) { puts(isspace(' ') ? "OK" : "Huh?"); return 0; } is a valid program with well defined behavior under C90, and violates a constraint in C99 and C11. An implementation that compiles it with no diagnostic is not a conforming C99 or C11 implementation (a bug if it claims to conform to C99 or C11). Of course the solution for programmers is easy. If you call isspace(), add "#include ", even if your code is only intended to be compiled as C90. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"