Thread: Simple #ifndef problem

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Simple #ifndef problem

    I always include an #ifndef.. #define in my header files to avoid mulltiple includes. This, however, doesn't seem to work under C. I get the following errors:
    stdhdrs.h(237): Warning! W129: #endif matches #if in different source file 'datatypes.h'
    eanfunc.h(237): Warning! W129: #endif matches #if in different source file 'datatypes.h'
    Here's thye code:
    Code:
    #ifndef DATATYPES_H_DEFINED
    #define DATATYPES_H_DEFINED
    //Code
    #endif
    Suggestions?

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    67
    shouldnt it be
    Code:
    #ifndef DATATYPES_H
    #define DATATYPES_H
    
    //CODE
    
    #endif

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The actual macro name is irrelevant, as long as it's the same for both the ifndef and the define.


    Can you post stdhdrs.h and eanfunc.h too? It's something in the way the use datatypes.h that causes the problem.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Thanks for the replies. I'm using Watcom C for my C projects. When I'm using the same methods on MsVC++ 6.0, everything works as intended.

    Stdhdrs.h, this file includes all the common headers for the project:
    Code:
    #ifndef STDHDRS_H_INCLUDED
    #define STDHDRS_H_INCLUDED
    
    #include <fcntl.h>
    #include <string.h>
    #include <stdio.h>
    #include <io.h>
    #include <conio.h>
    #include <memory.h>
    #include <bios.h>
    #include <graph.h>
    #include <stdlib.h>
    #include <math.h>
    #include <share.h>
    
    #include "datatypes.h"
    #include "mylib.h"
    
    #endif
    Datatypes.h, this file includes all the struct declarations, etc.. for the prog:
    Code:
    #ifndef DATATYPES_H_DEFINED
    #define DATATYPES_H_DEFINED
    
    #define word unsigned short
    
    #define DEBUG 0
    
    //....Lots of other types
    
    typedef struct keyboard_map{
    	char *name;
    	unsigned char value;
    } LOOKUP;
    
    #endif
    
    //Eanfunc.h
    #ifndef EANFUNC_H_INCLUDED
    #define EANFUNC_H_INCLUDED
    
    #include "datatypes.h"
    
    int ai[] = {
      {18},{14},{14},{14},{16},{0},{0},{0},{0},{0},{0},{6},{6},{6},{6},{6},{6},{6},{6},{6},
      {2},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{6},{6},{6},{6},{6},{6},{0},{0},{0},
      {0},{13}
    };
    
    char *fett[] = {
      {"1-"},{"1 "},{"1+"},{"2-"},{"2 "},{"2+"},{"3-"},{"3 "},{"3+"},{"4-"},{"4 "},{"4+"},{"5-"},{"5 "},{"5+"},{0}
    };
    
    char Ean13Read(char *kode, BC_13 *bar, char *type);
    void Ean13Write(char *achKode, double *dMenLev);
    char Ean13Check(char *achKode);
    char Ean128Read(char *kode, BC_128 *bar);
    
    #endif
    The only time i've seen this error elsewhere, is when i've given two macros the same name.

    Edited: I forgot to add Eanfunc.h
    Last edited by knutso; 06-02-2003 at 03:50 AM.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    Are there any more #ifs in Datatypes.h. For example do you use "#if DEBUG == 0" or anything? It looks to me that you open a #if without closing it with #endif somewhere in the section marked "//....Lots of other types" since what you have given us looks ok to me.
    DavT
    -----------------------------------------------

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    There are no mismatching #if..#endif statements.
    I've scanned through the whole project for this, and found none..

    I wonder if this could be a compiler issue?

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The error message sounds as if there was one #if* too many in datatypes.h.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I can't see any mismatch, attaching datatypes.h

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Very weird indeed...
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I tried the #if !defined(), with the same result as #ifndef..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in simple code.
    By richdb in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 02:45 AM
  3. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 09:10 PM
  4. Simple File I/O problem
    By Ignited in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2006, 10:49 AM
  5. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM