static variables and includes?

This is a discussion on static variables and includes? within the C++ Programming forums, part of the General Programming Boards category; why would that cause a stack overflow? - i mean, i need some bytes to store the texture. accessing the ...

  1. #31
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    why would that cause a stack overflow? - i mean, i need some bytes to store the texture. accessing the texture via the image would be slow....
    so what else should i use instead of an array?

    and what's about the class problem? :P

  2. #32
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, the stack is limited to about 2MB, so if you create a local variable of 1MB+, you have already used up half the stack in one fell swoop. Better to use a heap-allocation (new), and free it after use (delete).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #33
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    VC++ sets stack to 1 MB by default. You could increase this, but it's better to allocate on the heap (new/delete).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #34
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    whats that? is that a kind of array that is as fast as one?
    because i need to store the texture in some sort of array.
    in basic it would be
    Code:
    CreateBank()
    FreeBank()
    PokeInt(...)
    PeekInt(...)

  5. #35
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    Oh gods. You don't even know about the heap?
    http://www.cprogramming.com/tutorial...eory/heap.html
    http://www.cprogramming.com/tutorial/lesson6.html

    Long story short (KISS), the stack is the stack and the heap is the computer RAM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #36
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    you can use vector instead of array. It will allocate memory dynamically and handle it for you
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #37
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    hm ok. this seems better than an array.
    but there is still one question open: how do i do that thing with the classes?
    you said that i need to define the class in the virtualGL.h file and write it's functions to virtualGL.cpp

    but then the compiler says something like "___CLASS_NAME___ is not a class"
    umh...

  8. #38
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    Show the code, then.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #39
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    i did show the code here lately, but i will upload it again with the class

    http://www.dev-ch.de/upload/files/De...lGL2_Demo3.zip (1.64 MB)
    the class is called "vglTex" and is my texture class. if i get how it works, i will implement a matrix and a program class.

  10. #40
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    You only really need to show the code for the class...
    Well, it's defined in VirtualGL.h, so include VirtualGL.h in appropriate source files.
    And don't implement the functions in the header -_- Though we told you to do it in the source file.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #41
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    this code how it is gives me this error log:
    Code:
    1>------ Build started: Project: VirtualGL, Configuration: Debug Win32 ------
    1>Compiling...
    1>Matrix.cpp
    1>d:\martin\progs\c++\virtualgl\vgl-inc\virtualgl.h(6) : error C2065: 'SDL_Surface' : undeclared identifier
    1>d:\martin\progs\c++\virtualgl\vgl-inc\virtualgl.h(6) : error C2065: 'image' : undeclared identifier
    1>d:\martin\progs\c++\virtualgl\vgl-inc\virtualgl.h(6) : error C3861: 'SDL_LoadBMP': identifier not found
    1>d:\martin\progs\c++\virtualgl\vgl-inc\virtualgl.h(7) : error C2227: left of '->w' must point to class/struct/union/generic type
    1>        type is ''unknown-type''
    1>d:\martin\progs\c++\virtualgl\vgl-inc\virtualgl.h(8) : error C2227: left of '->h' must point to class/struct/union/generic type
    1>        type is ''unknown-type''
    1>d:\martin\progs\c++\virtualgl\vgl-inc\virtualgl.h(11) : error C3861: 'GetPixel': identifier not found
    1>d:\martin\progs\c++\virtualgl\vgl-inc\virtualgl.h(14) : error C3861: 'SDL_FreeSurface': identifier not found
    1>Sample.cpp
    1>d:\martin\progs\c++\virtualgl\vgl-inc\virtualgl.h(11) : error C3861: 'GetPixel': identifier not found
    1>d:\martin\progs\c++\virtualgl\vgl-inc\utility.h(2) : error C2365: 'GetPixel' : redefinition; previous definition was 'formerly unknown identifier'
    1>Generating Code...
    1>Build log was saved at "file://d:\Martin\Progs\C++\VirtualGL\Debug\BuildLog.htm"
    1>VirtualGL - 9 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    and you just told me that it would work.

    to the headers: i always thought that the function should be declared in the header file? or what else would it be good for??
    anyway, how do i finally get this class working in every cpp file?

  12. #42
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    It does work. You're just not doing it right. The header VirtualGL.h obviously needs to include other heads, specifically the SDL headers that contains the SDL_Surface header.

    It's very, very easy:
    Code:
    // Definition in .h file
    class CFoo
    {
    public:
    	void foo(int foo);
    };
    
    // Implementation - .cpp file.
    void CFoo::foo(int foo)
    {
    	// My code
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #43
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    oki now it's finaly working!
    great job guys! thanks a lot

  14. #44
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    oh wait! when i declare an object of the class vglTex like this:
    Code:
    vglTex tex;
    , the compiler tells me
    syntax error : missing ';' before identifier 'tex'
    what does that mean?

  15. #45
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    Usually means the compiler doesn't know what vglText is, so it thinks there must a ; after it.
    Which in essence means you haven't shown the compiler the class (or type) definition, which probably means you've probably not included the correct header.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 3 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. classes as member variables
    By Stonehambey in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2008, 08:01 PM
  2. Includes making me insane >.<
    By IceDane in forum C Programming
    Replies: 14
    Last Post: 04-14-2008, 11:24 AM
  3. global variables
    By shadovv in forum C++ Programming
    Replies: 7
    Last Post: 10-24-2005, 03:21 PM
  4. MingW & ProperySheet
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 06-27-2002, 08:34 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21