Thread: Weird Borland Warning

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Weird Borland Warning

    Ok trying to help a friend out that is in my class. When hey compile they get the following error
    Warn : HW4_HEADER.H(15,16):Cannot create pre-compiled header: initialized data in header
    The header is as follows (line bolded for the warning)
    Code:
    #ifndef MYHEADER_H_
    #define MYHEADER_H_
    
    #include <iostream.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    #define password 123
    #define bouns_min 50
    #define time_add_bouns 451
    
    #ifdef exturnvariable
       extern int bonus;
    #else
       int bonus;
    #endif
    
    #define full_time 40
    #define per 1.5
    
    
    enum option {Hourly=1, Salary, Commission, Quit};
    
    void Password_check(int);       //funtion prototype
    int Init();
    option Display_menu();
    void Process(option choose);
    void Hourly_salary(int, float);
    void Hourly_salary(int &,double &);
    void Commission_day(int);
    double Commission_earn(int);
    double Grand_total(double);
    void Pattern();
    #endif
    And yes I realize its pretty fugly but thats how our teacher wants it

    It does compile but I hate stupid warnings

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You can't initialize data in header files. If you do, Borland will not be able to create a pre-compiled header for you. It's really no big deal but pre-compiled headers will make compilation faster because unless you change the header...your compiler will not re-parse your version..it will use the pre-compiled one.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    But the data is not being initalized....

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you have K&R-2 (and why wouldn't you ), you'll read that
    int bonus;
    is a tentative definition.

    This is a kind of halfway house between a true declaration like
    extern int bonus;
    and a true definition like
    int bonus = 2;

    If you never get around to an explicit definition, the compiler will assume you meant
    int bonus = 0;

    If that's the way you're "supposed" to do it, I guess you have to turn off precompiled headers.
    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.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thanks Salem. No I don't have any books from K&R because I'm a cheap bastard.

    Personally I hate the fact that we have to use a global variable and that for the extra credit we have to move it into the header.

    Combine that with my distain for Borland and there is a lot of hate flying around

  6. #6
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Thantos
    Thanks Salem. No I don't have any books from K&R because I'm a cheap bastard.

    Personally I hate the fact that we have to use a global variable and that for the extra credit we have to move it into the header.

    Combine that with my distain for Borland and there is a lot of hate flying around
    Hmm, requiring a bad practice for extra credit. Sounds like in medical school giving extra credit to using leeches. Your instructor should be slapped.

    And what the 7734's wrong with Borland? Do you prefer that M$ crap better?

    And get a book. It's an investment. Be a cheap bastard where it counts. (again)
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Does you tutor even know what a tentative definition is?

    Or for that matter why you're mixing C and C++ headers (and its the old C++)
    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.

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I agree on slapping my instructor
    The reason I hate Borland is because it lets you get away with a lot, throws in its own functions, and seems to give a lot of lame warnings.
    I don't have any tutor but I don't think my instructor knows what a tentative definition is. The reason for the mixing of C & C++ headers is because its a "C" class that is being compiled as C++ and people can use the iostreams if they want.
    I have to go to my happy place during class to keep from screaming. For God's sake he thinks void main() is perfectly fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird things with my linked list of queue
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 11:23 PM
  2. weird
    By kiz in forum C Programming
    Replies: 8
    Last Post: 09-24-2007, 01:16 AM
  3. Weird Characters With GetDlgItemText
    By execute in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2006, 04:53 PM
  4. weird error
    By gandalf_bar in forum Linux Programming
    Replies: 2
    Last Post: 07-17-2005, 07:32 AM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM