Thread: next dumb question re header files

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    662

    next dumb question re header files

    my project is split over several files so i need to declare the function bool toggle_turn(void) in a header file so main can find it. when i try to compile to test everything so far i get an error saying bool is undefined.

    a) do i need to include the stdbool.h file in my own header file
    b) if so do i need to declare it in main and the other source files as well.

    many thanks
    coop

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,926
    You should #include <stdbool.h> wherever you use bool, so yes for both. In theory you can avoid including it in the file containing the main function since it would be included via your own header, but that makes for fragile code if you do mention bool in that source file.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    thanks for the reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Header files question
    By Programmer_P in forum C++ Programming
    Replies: 8
    Last Post: 05-14-2009, 01:16 PM
  2. quick question about header files
    By linucksrox in forum C++ Programming
    Replies: 11
    Last Post: 08-24-2005, 09:24 PM
  3. Novice question on header files
    By hern in forum C++ Programming
    Replies: 1
    Last Post: 07-30-2005, 10:11 AM
  4. quick question about header files
    By Kirstin in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2001, 11:21 AM
  5. question about header files
    By ArseMan in forum C++ Programming
    Replies: 2
    Last Post: 09-21-2001, 02:33 AM

Tags for this Thread