Re: Runtime errors possible when I forgot include <string.h>



Le 25-10-2005, ABeck <alexander.beck-ratzka@xxxxxxxxxx> a écrit :
> I have ar more or less academical question.
>
> Can there arise runtime errors in a program, if the include of
><string.h> has been forgotten? If all the arguments to the functions of
><string.h> are correct, is it possible that an error occurs, and what
> an error might this be?

Without include of <string.h>, all functions are 'implicitely
defined', that is return value is supposed to be int and
parameters are converted using 'default argument promotion'
(6.5.2.2/6), ie integer promotion and float->double.

So, the generated code could be incompatible with the
implementation (UB). If implicit conversion between
int and char* is unsafe (sizeof(int) < sizeof(char*)
for example), then, strange things will occur.

But, in most platform, implict conversion
between int and char* behaves in a way such that
the code runs.

Marc Boyer
.



Relevant Pages

  • Re: Sort of mystified from an earlier thread
    ... In C there is an implicit conversion from char to int. ... Java trolls often bring this up. ...
    (comp.lang.c)
  • Re: Moving from 8051 to AVR
    ... bit integer types of signed and unsigned char. ... The reason is that on 8 bit machines a 16 bit int requires 2 fetches ... Also if the items being operated on are 8 bit integer types ... instructed to turn off the integer promotion. ...
    (comp.arch.embedded)
  • Re: Integer promotion with conditional operator
    ... clang seems to think that the type of the conditional expression is int. ... the prototype for prinf, beyond the char * for the "format string", the ... undergo integer promotion. ...
    (comp.lang.c)
  • Re: Runtime errors possible when I forgot include
    ... > that is return value is supposed to be int and parameters are converted using ... > If implicit conversion between int and char* is unsafe < ... 64-bit platforms now still have 32-bit int, and then there's still the odd LP32 ...
    (comp.lang.c)
  • Re: sizeof operator
    ... >> Why do they write char if they mean int? ... > lookup Integer Promotion ... This has nothing to do with integer promotion. ...
    (comp.lang.c)