Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Major problem with header files

Major problem with header files

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorialquestion
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sGrabert
    wrote on last edited by
    #1

    Hello, I have a major problem with the .h header files. The Compiler (VS2003) does not seem to care about my function definition in the header file if implemented in another .cpp file. Here is an example: [myfunc.h] #pragma once int DLLInit(char* DLLInfo); [myfunc.cpp] #include "myfunc.h" int DLLInit(int DLLInfoInt) { return 0; } I seem to be missing the whole point of a header file if the compiler does not detect the false declaration of variable name and type.... :wtf: I want to include the header file in the project using the dll, too, so it is important to check parameter and type of function parameters, etc.:confused: Maybe this is a very simple problem but I can't find a solution yet.. Any help? thx in advance

    T C 2 Replies Last reply
    0
    • S sGrabert

      Hello, I have a major problem with the .h header files. The Compiler (VS2003) does not seem to care about my function definition in the header file if implemented in another .cpp file. Here is an example: [myfunc.h] #pragma once int DLLInit(char* DLLInfo); [myfunc.cpp] #include "myfunc.h" int DLLInit(int DLLInfoInt) { return 0; } I seem to be missing the whole point of a header file if the compiler does not detect the false declaration of variable name and type.... :wtf: I want to include the header file in the project using the dll, too, so it is important to check parameter and type of function parameters, etc.:confused: Maybe this is a very simple problem but I can't find a solution yet.. Any help? thx in advance

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      sGrabert wrote:

      [myfunc.h] #pragma once int DLLInit(char* DLLInfo); [myfunc.cpp] #include "myfunc.h" int DLLInit(int DLLInfoInt) { return 0; }

      check your code once again... you declare a function that gets a char*, but you define a function that gets an int... why the compiler wouldn't complain then ? :rolleyes:


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      1 Reply Last reply
      0
      • S sGrabert

        Hello, I have a major problem with the .h header files. The Compiler (VS2003) does not seem to care about my function definition in the header file if implemented in another .cpp file. Here is an example: [myfunc.h] #pragma once int DLLInit(char* DLLInfo); [myfunc.cpp] #include "myfunc.h" int DLLInit(int DLLInfoInt) { return 0; } I seem to be missing the whole point of a header file if the compiler does not detect the false declaration of variable name and type.... :wtf: I want to include the header file in the project using the dll, too, so it is important to check parameter and type of function parameters, etc.:confused: Maybe this is a very simple problem but I can't find a solution yet.. Any help? thx in advance

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        sGrabert wrote:

        I seem to be missing the whole point of a header file if the compiler does not detect the false declaration of variable name and type....

        Why would it ? Function overloading is possible in C++ and you don't need to have a declaration for your functions. So, in your case you have a declaration of a function but no body for this function. As long as you don't call that function, everything will be fine. But once you call that function, you'll get a linker error. So, actually, what is your real problem ? I don't understand what you are trying to achieve...


        Cédric Moonen Software developer
        Charting control [v1.2]

        T S 2 Replies Last reply
        0
        • C Cedric Moonen

          sGrabert wrote:

          I seem to be missing the whole point of a header file if the compiler does not detect the false declaration of variable name and type....

          Why would it ? Function overloading is possible in C++ and you don't need to have a declaration for your functions. So, in your case you have a declaration of a function but no body for this function. As long as you don't call that function, everything will be fine. But once you call that function, you'll get a linker error. So, actually, what is your real problem ? I don't understand what you are trying to achieve...


          Cédric Moonen Software developer
          Charting control [v1.2]

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          Cedric Moonen wrote:

          you have a declaration of a function but no body for this function. As long as you don't call that function, everything will be fine.

          that's not true anymore under VS2005 AFAIK (but didn't tested actually)...


          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          C M 2 Replies Last reply
          0
          • C Cedric Moonen

            sGrabert wrote:

            I seem to be missing the whole point of a header file if the compiler does not detect the false declaration of variable name and type....

            Why would it ? Function overloading is possible in C++ and you don't need to have a declaration for your functions. So, in your case you have a declaration of a function but no body for this function. As long as you don't call that function, everything will be fine. But once you call that function, you'll get a linker error. So, actually, what is your real problem ? I don't understand what you are trying to achieve...


            Cédric Moonen Software developer
            Charting control [v1.2]

            S Offline
            S Offline
            sGrabert
            wrote on last edited by
            #5

            Why would it ? Function overloading is possible in C++ and you don't need to have a declaration for your functions. So, in your case you have a declaration of a function but no body for this function. As long as you don't call that function, everything will be fine. But once you call that function, you'll get a linker error. Okay, I called the function and finally :-O got a linker error, I was expecting an error during compiling... I developed using Delphi the last 5 years and the ambigious overloading of types/variables/function C++ without any visible effect is driving me crazy... In Delphi you had to add OVERLOAD or use a typecast.. The main reason for this problem: - i want to create a dll that can be called from another app, using dynamic linking - works so far - I changed the implementation of a function (by accident) and got a very confusing exception after calling the function from the dll but no compiler error, though i linked the header file from the dll.

            C 1 Reply Last reply
            0
            • T toxcct

              Cedric Moonen wrote:

              you have a declaration of a function but no body for this function. As long as you don't call that function, everything will be fine.

              that's not true anymore under VS2005 AFAIK (but didn't tested actually)...


              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              toxcct wrote:

              that's not true anymore under VS2005 AFAIK (but didn't tested actually)...

              I never heard of that and I hardly imagine that... Suppose that you have three files: - One main.cpp that contains the main function - One header file (file.h) that contains a function declaration - One cpp file (file.cpp) that contains the function definition (of the previous function). Suppose that you call this function in the main function. How can the compiler know, when compiling main.cpp that this function is actually defined in file.cpp ? What if you didn't include file.cpp in your project ? Thus the error is generated at link time, when the linker cannot find the compiled function in the object files.


              Cédric Moonen Software developer
              Charting control [v1.2]

              T 1 Reply Last reply
              0
              • S sGrabert

                Why would it ? Function overloading is possible in C++ and you don't need to have a declaration for your functions. So, in your case you have a declaration of a function but no body for this function. As long as you don't call that function, everything will be fine. But once you call that function, you'll get a linker error. Okay, I called the function and finally :-O got a linker error, I was expecting an error during compiling... I developed using Delphi the last 5 years and the ambigious overloading of types/variables/function C++ without any visible effect is driving me crazy... In Delphi you had to add OVERLOAD or use a typecast.. The main reason for this problem: - i want to create a dll that can be called from another app, using dynamic linking - works so far - I changed the implementation of a function (by accident) and got a very confusing exception after calling the function from the dll but no compiler error, though i linked the header file from the dll.

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                sGrabert wrote:

                - I changed the implementation of a function (by accident) and got a very confusing exception after calling the function from the dll but no compiler error, though i linked the header file from the dll.

                What did you change exactly ? Because if the linker doesn't find an implementation for the function, it will show you a link error.


                Cédric Moonen Software developer
                Charting control [v1.2]

                S 1 Reply Last reply
                0
                • C Cedric Moonen

                  toxcct wrote:

                  that's not true anymore under VS2005 AFAIK (but didn't tested actually)...

                  I never heard of that and I hardly imagine that... Suppose that you have three files: - One main.cpp that contains the main function - One header file (file.h) that contains a function declaration - One cpp file (file.cpp) that contains the function definition (of the previous function). Suppose that you call this function in the main function. How can the compiler know, when compiling main.cpp that this function is actually defined in file.cpp ? What if you didn't include file.cpp in your project ? Thus the error is generated at link time, when the linker cannot find the compiled function in the object files.


                  Cédric Moonen Software developer
                  Charting control [v1.2]

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #8

                  hum, actually, i was more saying that the compiler (or maybe the linker in fact) will throw a warning if you declare a function (in a .h mostly) that is never defined...


                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  S M 2 Replies Last reply
                  0
                  • T toxcct

                    hum, actually, i was more saying that the compiler (or maybe the linker in fact) will throw a warning if you declare a function (in a .h mostly) that is never defined...


                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    S Offline
                    S Offline
                    sGrabert
                    wrote on last edited by
                    #9

                    hum, actually, i was more saying that the compiler (or maybe the linker in fact) will throw a warning if you declare a function (in a .h mostly) that is never defined... This is a helpfull warning indeed ;), VS2003 fails to warn you about this.

                    1 Reply Last reply
                    0
                    • C Cedric Moonen

                      sGrabert wrote:

                      - I changed the implementation of a function (by accident) and got a very confusing exception after calling the function from the dll but no compiler error, though i linked the header file from the dll.

                      What did you change exactly ? Because if the linker doesn't find an implementation for the function, it will show you a link error.


                      Cédric Moonen Software developer
                      Charting control [v1.2]

                      S Offline
                      S Offline
                      sGrabert
                      wrote on last edited by
                      #10

                      (i renamed the caption to "minor", seems more appropriate) workflow: 1. DLL 1a. creating the dll.h file with function prototypes 1b. creating the dll.cpp file with function implementation (the dll itself does not use the functions, so no linking check here!) 2. app 2a. dynamic loading of dll using dll.h I wanted to ensure the correct calling of functions in the app using the .h file: (i have cut all the class stuff etc.) [dll.h] int DLLInit(char* DLLInfo); [app.h] #include "dll.h" typedef bool (*DLLINIT)(char* DLLInfo); DLLINIT pDLLInit; pDLLInit= (DLLINIT)::GetProcAddress(m_DLL, "DLLInit"); Is this possible (or even useful) in any way? -- modified at 5:50 Thursday 23rd August, 2007

                      1 Reply Last reply
                      0
                      • T toxcct

                        Cedric Moonen wrote:

                        you have a declaration of a function but no body for this function. As long as you don't call that function, everything will be fine.

                        that's not true anymore under VS2005 AFAIK (but didn't tested actually)...


                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #11

                        toxcct wrote:

                        that's not true anymore under VS2005 AFAIK

                        It's still true ;P

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        T 1 Reply Last reply
                        0
                        • M Mark Salsbery

                          toxcct wrote:

                          that's not true anymore under VS2005 AFAIK

                          It's still true ;P

                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                          T Offline
                          T Offline
                          toxcct
                          wrote on last edited by
                          #12

                          i expressed myself badly. read further[^]


                          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                          1 Reply Last reply
                          0
                          • T toxcct

                            hum, actually, i was more saying that the compiler (or maybe the linker in fact) will throw a warning if you declare a function (in a .h mostly) that is never defined...


                            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                            M Offline
                            M Offline
                            Mark Salsbery
                            wrote on last edited by
                            #13

                            No warning/error there either :)

                            Mark Salsbery Microsoft MVP - Visual C++ :java:

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups