Basic problem solving

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mamp
    New Member
    • Jul 2007
    • 3

    Basic problem solving

    In my new developed Visual C++ 6 project I derived about 4 new classes based upon CDialog base class. In later stage I required to add a greate number of CString type variables. (the line numbers exceeded 4600) When I declared them in a existing Class header file, it seems the the compiler limit exceeded. Could not compile with 2 or 3 standard limite completes. Then I created a new header file through 'project insert - header file', with #def MYHEADER.H, also tried #ifndef cplusplus #def etc. Put all new variable declaration in that file. But compiler halts at "Generating Code". I worked further, splitted declarations is small header files. I tried #pragma pack(n). But all is halted. Could somebody solve this problem.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    First, you do not declare variables in a header file.

    Header files are to contain only declarations and not definitions.

    A declaration says a thing exists.
    A definition creates it.

    Variables in header files are usually global variables. If so, there is a limit to global memory in a program. That can cause a program with a lot of globals tto not build.

    Variables in header files are created each time the header is included. This can cause the linker to fail when there are many variables with the same name in the same scope.

    Variables declared in functions as local variables go into the functions stack frame. Here again, there may ne limits to stack memory that will crash your program at run time.

    You need to:

    1) remove all variables from your header files.
    2) allocate your 4600 CStrings yourself using the new operator. That will put the strings on the heap where there is effectively no size limit.
    3) you delete the strings when you are finished with them.

    This will let you pass the strings around by pointer or reference.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by weaknessforcats
      First, you do not declare variables in a header file.

      Header files are to contain only declarations and not definitions.
      1s/declare/define/

      kind regards,

      Jos (<--- nitpicker ;-)

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by JosAH
        1s/declare/define/
        Dang! I mean't define. I was thinking define. But you only declare in a header file so that's what I typed. Geez!

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by weaknessforcats
          Dang! I mean't define. I was thinking define. But you only declare in a header file so that's what I typed. Geez!
          That's the dexter sapiens syndrome; I suffer from it too: fingers that start thinking
          for themselves ;-)

          kind regards,

          Jos

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Originally posted by JosAH
            dexter sapiens syndrome
            Windows folks call that a PEBCAK error.

            (Problem Exists Between Chair And Keyboard).

            I must admit dexter sapiens is far more cultured and rolls off the tongue with flavors of erudition.

            PEBCAK is more like HOCK-A-PAT-TOO-EE.

            Must be a Saxon/Norman thing still lingering from 1066.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by weaknessforcats
              Windows folks call that a PEBCAK error.

              (Problem Exists Between Chair And Keyboard).

              I must admit dexter sapiens is far more cultured and rolls off the tongue with flavors of erudition.

              PEBCAK is more like HOCK-A-PAT-TOO-EE.

              Must be a Saxon/Norman thing still lingering from 1066.
              Nononono, it's more like a PEBBAF syndrome so to speak; It's a Problem
              Exists Between Brains And FIngers thingie; your brains want your fingers to
              type, say, "main" and your fingers go "make"; little rascals they are. You
              want to type "integral" and your fingers go "int i;" all by themselves.

              It's got nothing to do with chairs, nor with the battle of Hastings; it's just those
              bloody fingers that think they know better ;-)

              kind register,

              Jav^H^Hove^H^H< stop it!>syste^H^H^H ^H<cut that out!> ;-)

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Ok guys. I think we all get the picture.

                Comment

                • mamp
                  New Member
                  • Jul 2007
                  • 3

                  #9
                  Thank you JosAH. I came from the C world. Since DOS vanished I turned to this VB. Since it seem limitations I entered at VC++ 6. All where I learned to declare variables in header files (except vb) for globals sake. Things are not so straight forward to operate with 'new' and 'delete'. Your suggestion is under thinking process. But it would be glad if the things were as thought.

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by mamp
                    Thank you JosAH. I came from the C world. Since DOS vanished I turned to this VB. Since it seem limitations I entered at VC++ 6. All where I learned to declare variables in header files (except vb) for globals sake. Things are not so straight forward to operate with 'new' and 'delete'. Your suggestion is under thinking process. But it would be glad if the things were as thought.
                    Actually it was WeaknessForCats who explained it all to you. For the new and
                    delete operators you can think of malloc and free for simplicity; the objects
                    your create and destroy that way are the dynamic objects in your program.

                    the 'new' operator invokes one of your constructors in your class and the delete
                    operator invokes the destructor of your class.

                    kind regards,

                    Jos

                    Comment

                    • mamp
                      New Member
                      • Jul 2007
                      • 3

                      #11
                      Jos,

                      Finally I managed to work with 'structure'. This is salient feature as all you know well. But in the game of hideous MFC, I just put aside 'structure'. I preferred it over 'new'. Worked well.

                      kind regards,

                      mamp

                      Comment

                      Working...