Compile error ?

This is a discussion on Compile error ? within the C Programming forums, part of the General Programming Boards category; I am not experienced in c programming. I met a compile error like following [gary@localhost hw10]$ gcc prog1.c hw10.c:5: error: ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    32

    Compile error ?

    I am not experienced in c programming.
    I met a compile error like following

    [gary@localhost hw10]$ gcc prog1.c
    hw10.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘isLeap’

    I searched on google and found quite a few people have similar errors like me.
    Someone comment this is because losing semicolon in struct definition or so.
    I just check it out
    but still not work.

    More strange, if I use g++ to compile
    it woks.
    [gary@localhost hw10]$ g++ prog1.c
    [gary@localhost hw10]$

    But I think I am writing original c codes without any c++ syntax?


    Here is the codes
    prog1.c

    Code:
    #include <stdio.h>
    #include "book.h"
    #include "date.h"
    
    bool isLeap(int year) {
       if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) return true;
       else return false;
    };
    book.h
    Code:
      1 #ifndef BOOK_H
      2 #define BOOK_H
      3
      4 enum Type {NOVEL, COMICS, MANUAL, TEXTBOOK};
      5
      6 struct Book{
      7    char title[128];
      8    enum Type type;
      9    char ISBN[128];
     10    char authors[128];
     11    unsigned int importance;
     12 };
     13
     14 #endif
    date.h
    Code:
      1 #ifndef DATE_H
      2 #define DATE_H
      3
      4 struct Date {
      5    unsigned int year;
      6    unsigned int month;
      7    unsigned int day;
      8 };
      9
     10 #endif
    I would really apprecite for any comment..

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,819
    Quote Originally Posted by ovid
    But I think I am writing original c codes without any c++ syntax?
    The bool keyword is from C++, although it is available in C with respect to the 1999 edition of the C standard, which is not the default for gcc.
    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
    Feb 2010
    Posts
    32
    Now it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Linking to shlwapi.lib in C, MSVC CMD.
    By Joerge in forum Windows Programming
    Replies: 4
    Last Post: 08-07-2009, 05:18 PM
  3. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21