Thread: Structs declaration on header with a problem in main.c file

  1. #1
    Registered User
    Join Date
    Jan 2022
    Posts
    2

    Structs declaration on header with a problem in main.c file

    yea

    I declared a struct on the header file called "entity", with a typedef.

    entity.h
    Structs declaration on header with a problem in main.c file-screenshot-2022-01-02-22-50-00-jpg

    I created a new file called "entity.c", with the methods thinking a data encapsulation

    entity.c
    Structs declaration on header with a problem in main.c file-screenshot-2022-01-02-22-52-45-jpg

    But when I use in my main.c, the #include doesn't work and the compiler shows an error of syntax (it doesn't find any struct called entity) and it returns some warnings about the implicit declaration of functions. I can't find where is the problem, because the entity.h is declared.

    main.c
    Structs declaration on header with a problem in main.c file-screenshot-2022-01-02-23-03-49-jpg

    GCC Warnings and Errors
    Structs declaration on header with a problem in main.c file-screenshot-2022-01-02-23-04-34-jpgStructs declaration on header with a problem in main.c file-screenshot-2022-01-02-23-04-43-jpg

    What exactly is the problem, since I declared the header file?

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Your include guard is wrong. Instead of #ifdef it should be #ifndef
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Jan 2022
    Posts
    2
    Quote Originally Posted by john.c View Post
    Your include guard is wrong. Instead of #ifdef it should be #ifndef
    Oh yea, I spent hours searching on internet and I couldn't find out.
    I didn't know it was a silly mistake

    thx

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    A single missing letter like that can be insanely hard to spot. Remember to use the maximum warning level (for gcc use -Wall -Wextra -Wpedantic). Maxing out the warning level can point out some similar mistakes, although unfortunately not that one. Still, you'll never make that mistake again!

    #pragma once is a better solution but not as portable.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    guifary2, for future reference, post your text between [code][/code] tags.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by john.c View Post
    A single missing letter like that can be insanely hard to spot. Remember to use the maximum warning level (for gcc use -Wall -Wextra -Wpedantic). Maxing out the warning level can point out some similar mistakes, although unfortunately not that one. Still, you'll never make that mistake again!

    #pragma once is a better solution but not as portable.
    I wish I could say I would never make the same mistake another time.

    I have actually found an answer to a problem I had where I had posted the answer over a decade before.
    And, I have no memory of doing the post or having the problem.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. std::string declaration in header file error
    By loumbut5 in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2016, 08:35 AM
  2. Placing structs on header file
    By Bryan_James in forum C Programming
    Replies: 2
    Last Post: 02-19-2015, 07:20 AM
  3. Replies: 16
    Last Post: 04-05-2014, 09:23 PM
  4. Replies: 11
    Last Post: 09-25-2011, 12:22 AM
  5. Redefinition error with repititions of header file declaration
    By shrink_tubing in forum C++ Programming
    Replies: 5
    Last Post: 08-02-2010, 12:07 AM

Tags for this Thread