Thread: undeclared identifier problem

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    50

    undeclared identifier problem

    I'm just beginning to learn about moving functions out of the main program.

    I've got a BITMAP_FILE_PTR undeclared identifier error in MSVC 6.0 .

    I created a header file called bitmapfunct involving BITMAP_FILE_PTR and now I get an error.

    I declared the function in my main but how do I make it so it is also declared or defined in the header file ?

    Here is the code from my main involving the variable

    Code:
    typedef struct BITMAP_FILE_TAG
            {
            BITMAPFILEHEADER bitmapfileheader;  // this contains the bitmapfile header
            BITMAPINFOHEADER bitmapinfoheader;  // this is all the info including the palette
            PALETTEENTRY     palette[256];      // we will store the palette here
            UCHAR            *buffer;           // this is a pointer to the data
    
            } BITMAP_FILE, *BITMAP_FILE_PTR;
    do I use extern ?

    extern BITMAP_FILE_PTR

    ?

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Can you post the exact code where the problem occurs?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    the error happens in the bitmapfunct.h header file. You are right. Sorry here is the code where the error actually occurs.


    Code:
    /*
    header file  bitmapfunct.h
    */
    
    #ifndef bitmapfunct_h
    #define bitmapfunct_h
    
    //prototypes
    
    
    
    int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename);
    int Unload_Bitmap_File(BITMAP_FILE_PTR bitmap);
    int Flip_Bitmap(UCHAR *image, int bytes_per_line, int height);
    
    
    
    
    
    // FUNCTIONS //////////////////////////////////////////////
    
    
    
    
    /////// load bitmap file function
    
    
    int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename)
    {
    // this function opens a bitmap file and loads the data into bitmap
    
    int file_handle,  // the file handle
        index;        // looping index
    
    UCHAR *temp_buffer = NULL; // used to convert 24 bit images to 16 bit
    OFSTRUCT file_data;        // the file data information
    
    // open the file if it exists
    if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1)
       return(0);
    
    // now load the bitmap file header
    _lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));
    
    // test if this is a bitmap file
    if (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
       {
       // close the file
       _lclose(file_handle);
    
       // return error
       return(0);
       } // end if
    I posted a little more than necessary to give you an idea of what is happening.

    The error occurs where it says " int Load_Bitmap_File(Bitmap_File_PTR bitmap, char *filename);
    "


    Trying to break up a program that works by itself into smaller ones with functions so that I can make it bigger and more complex but still readable.
    Last edited by jjj93421; 04-23-2004 at 04:58 AM.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    actually, I'm having a lot of problems......



    Compiling...
    bitmapanim.cpp
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(12) : error C2065: 'BITMAP_FILE_PTR' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(12) : error C2146: syntax error : missing ')' before identifier 'bitmap'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(12) : error C2059: syntax error : ')'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(13) : error C2146: syntax error : missing ')' before identifier 'bitmap'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(13) : error C2059: syntax error : ')'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(28) : error C2146: syntax error : missing ')' before identifier 'bitmap'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(28) : error C2086: 'Load_Bitmap_File' : redefinition
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(28) : error C2059: syntax error : ')'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(29) : error C2143: syntax error : missing ';' before '{'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(29) : error C2447: missing function header (old-style formal list?)
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(188) : error C2146: syntax error : missing ')' before identifier 'bitmap'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(188) : error C2086: 'Unload_Bitmap_File' : redefinition
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(188) : error C2059: syntax error : ')'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(189) : error C2143: syntax error : missing ';' before '{'
    c:\program files\microsoft visual studio\myprojects\bitmap anim (broken up)\bitmapfunct.h(189) : error C2447: missing function header (old-style formal list?)

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    How is the compiler supposed to know what "BITMAP_FILE_PTR " is?
    You need to #include the header file containing that definition.

    Since you're using other Win32 definitions, you definitely need #include <windows.h>

    gg

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    ok,

    question:

    If I'm planning on breaking up a program that is a single file and put the functions in other files, do I need classes to do that?

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    The concept equally applies to regular functions.

    Read this thread (and the thread I reference in there).

    Post back here if you have any questions.

    gg

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    49
    Move your declaration of your BITMAP_FILE_TAG to bitmapfunct.h
    Hello, everyone.

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You are misusing header files.

    The only things that belong in header files are classes, non-intialized structs, defines, constants, prototypes, etc.

    Do not put function bodies in header unless it is an inline function. The rules I follow for inlining functions are: 1. Is is short? - it doesn't do much. 2. Is it called frequently. If 1 and 2 are not true then it is not inlined.

    Example:

    Matrix.h
    Code:
    #ifndef _MATRIX_
    #define _MATRIX_
    
    #define SUCCESS 0
    #define FAILURE -1
    
    class Matrix
    {
      protected:
         float *MyMatrix;
         int numrows;
         int numcols;
         int sizeinbytes;
      public:
        Matrix(void) {};
        ~Matrix(void) {if (MyMatrix) delete [] MyMatrix;};
       
        bool Init(int _numrows,int _numcols);
        void Identity(void);
        void Translation(float dx,float dy,float dz);
    };
    
    #endif
    Matrix.cpp
    Code:
    #include "Matrix.h"
    
    bool Matrix::Init(int _numrows,int _numcols)
    {
      //code here...
    }
    
    void Matrix::Identity(void)
    {
      //code here....
    }
    
    void Matrix::Translation(float dx,float dy,float dz)
    {
      //code here....
    }
    Last edited by VirtualAce; 04-23-2004 at 09:01 AM.

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >#ifndef _MATRIX_
    >#define _MATRIX_
    Leading underscores followed by any upper case letter are reserved by the implementation.
    My best code is written with the delete key.

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Whatever that means. Anyways use some way to define your headers so that they are not included multiple times.

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Whatever that means.
    It means that I can't match your ASM l33tness, so I assert myself by nitpicking your C++. Or it means that leading underscores are error prone and incorrect in standard C++ and you should avoid them. You can pick.
    My best code is written with the delete key.

  13. #13
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    So the actual function body can't be in a header file ?

    Ok, well, that is what I was doing wrong then.

  14. #14
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607


    Ok...so drop the underscores and do what Prelude says. I'm reading a book right now about C99 but gimme a break the thing is like 900 pages long....so I'm not up on all the standards yet.





    No worries...my first program in C totally abused headers. I thought they were simply modules - text files that were combined with the main module to create the program. Header files are simply for placing everything there that normally goes above your function bodies. In other words, your source files will usually only have an include in them and then the function bodies. All of the preliminary stuff like #defines, structs, classes, prototypes, etc. will go into the headers. That's really the simplest explanation I can think of. To avoid namepsace clashes with functions either use classes or namespaces. Yet another explanation is probably begging to be written there...but perhaps not.




    Oh and I'm not really as good as some at assembly IMO - I know enough to get the job done.

    And for those that think its not necessary I'm using it in Direct3D too. Nothing does extremely fast memory to memory copies like assembly language and that is really what I use it for. Yeah you can use memset....but....I don't. Filling vertex buffers, doing texture to texture writes (in software), etc. are all great spots for assembly. Given that video card resources are scarce your super fast texture to texture write may just be executing in software because the card said.....sorry, charlie, we don't have enough memory or resources for that. Even with all the modern technology you cannot rely on hardware to do everything for you...there's just not enough resources for that yet.
    Last edited by VirtualAce; 04-24-2004 at 09:34 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem
    By ExDHaos in forum C++ Programming
    Replies: 12
    Last Post: 05-22-2009, 04:50 AM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Driver Problem
    By todd14 in forum C Programming
    Replies: 3
    Last Post: 04-04-2007, 11:46 PM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Maximizing a Console Window Full Screen
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 08-13-2004, 02:27 AM