a problem with header files 
Author Message
 a problem with header files

I have the following problem.
While using a book a copied a program that used the command Exit(1)
Though the programming book says that you need Stdlib.h The program i copied
did not use it.
The book also came with a CD with the source code for all the projects and
it also di not have Stdlib.h
Am i crazy or should the pre-made program not work, because it does.
P.S. I'm using a Borland compiler



Tue, 22 Aug 2000 03:00:00 GMT  
 a problem with header files

Quote:

> I have the following problem.

        This doesn't sound like a problem.  ;)

Quote:
> While using a book a copied a program that used the command Exit(1)
> Though the programming book says that you need Stdlib.h The program i copied
> did not use it.
  !-------------!
> The book also came with a CD with the source code for all the projects and
> it also di not have Stdlib.h

     !------------------------!

        Important question here.  You say in one statement that "The program
[you] copied did not use it," while in another you appear to say that the
CD-ROM with the source code "also did not have stdlib.h"

        So the question is, what do you mean by 'using' stdlib.h?

        If you examine the source code, it should either have a line in the
source file that says

        #include <stdlib.h>

        or, it should include another source file, and one of those other
files has stdlib.h included.

        If on the other hand, you are looking for a file called stdlib.h
to copy out of the book, or locate on the CD-ROM, you will not find such
a header file.  The stdlib.h header file is included with all standard C
compilers.

                                                        -- Stonelight



Tue, 22 Aug 2000 03:00:00 GMT  
 a problem with header files

Quote:

>I have the following problem.
>While using a book a copied a program that used the command Exit(1)

I hope you mean that it makes a function call exit(1). Remember C is case
sensitive and doesn't have commands (other than perhaps the strings you
pass to the system() function).

Quote:
>Though the programming book says that you need Stdlib.h The program i copied
>did not use it.

Again C is case sensitive, you should #include <stdlib.h> to ensure that
there is an appropriate declaration in scope for exit().

Quote:
>The book also came with a CD with the source code for all the projects and
>it also di not have Stdlib.h
>Am i crazy or should the pre-made program not work, because it does.

When you leave out the #include <stdlib.h> you invoke undefined behaviour
at the call to exit() because C assumes that an undeclared function returns
int when called while exit() returns void. That means that there are no
guaratees that the compiler will generate the right machine code to call the
function correctly. Undefined behaviour means anything can happen, from the
program crashing horribly to (in some sense) working. There's noting that
requires it to fail just as there's nothing that requires it to work. Fix
the program by adding the required #include <stdlib.h> and it will then work
because it is well-defined according to the C language definition, rather
just by accident.

--
-----------------------------------------


-----------------------------------------



Wed, 23 Aug 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with header files

2. Problems with header file, etc.

3. Simple compile problem with header file

4. problem with header file (.h)

5. Problem: Using header files

6. problem getting header file for the COM dll that uses msado15.dll

7. Problem with header files.

8. Problem compiling header files

9. BOOL problem with header file

10. Problem with header files

11. Help! Having problems combining header files, malloc, and **pointers

12. #ifndef/#ifdef problems in my header file (conditional header inclusion)

 

 
Powered by phpBB® Forum Software