Re: integer and floating-point bit pattern

From: Jack Klein (jackklein_at_spamcop.net)
Date: 10/02/03


Date: Thu, 02 Oct 2003 03:38:42 GMT

On 1 Oct 2003 13:56:10 -0700, nethlek@tokyo.com (Mantorok Redgormor)
wrote in comp.lang.c:

> Would the following determine if the bit pattern for
> floating point 0.0 and integer 0 are the same?
>
> #include <stdio.h>
> int main(void)
> <%
> if(0 == 0.0f)
> puts("Bit pattern is the same.");
>
> return 0;
> %>
>
>
> Also is it undefined behavior for failure
> to include the proper header file for any
> function or just functions that accept a
> variable number of arguments?

Mike already answered your first question, he was a little unsure
about the second.

It is not and has never been a requirement in C that you include
header files, except in a few cases where data types with
implementation-defined types and members (such as time_t, FILE, etc.).

Prior to the current (1999) standard you did not need a prototype or a
declaration to call a function that returned int and accepted a fixed
number and type of arguments, if all the argument types were those
provided by default promotions.

Under the current standard, there must be at least a declaration in
scope for any function you call, specifying the return type. Implicit
int is illegal, including the return type of functions. The
declaration does not need to be a prototype if the function accepts a
fixed number and type of arguments if the types are the default
promotions.

Since the very first 1989 ANSI standard, it produces undefined
behavior to call a variadic function without a full prototype in
scope.

It is perfectly valid under all versions of the C standard to provide
your own prototype for a standard function so long as you get it
correct.

If you write a prototype equivalent to:

   char *strchr(const char *s, int c);

...then you can call this function without including <string.h>.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq


Relevant Pages

  • Re: custom header files
    ... with the prototype declarations) were included in a header file. ... when I make function calls to any of the standard C ... were stored in a header file in the standard C library. ... what I'm wanting to do is make any functions that I create ...
    (comp.programming)
  • Re: integer and floating-point bit pattern
    ... >> Also is it undefined behavior for failure ... > Prior to the current standard you did not need a prototype or a ... > declaration to call a function that returned int and accepted a fixed ...
    (comp.lang.c)
  • Re: General question
    ... declaration for, it assumed that it was a function returning an int ... The first true C standard, ANSI/ISO of 1989 and 1990, changed things. ... Its prototype is: ...
    (comp.lang.c)
  • Re: passing a type of different KIND to a C function from Fortran binding
    ... call (since the ellipsis in a prototype doesn't specify types), ... unsigned int, and 'float' is converted to double. ... This is in the C standard since C89, ... The standard specifies conversion to the ...
    (comp.lang.fortran)
  • Re: How can I do sort program for unsorted setup file?
    ... we have had a standard for C ... main has return type int. ... exit() is prototyped/declared in. ... There was no prototype for customer_input, ...
    (comp.lang.c)