Like Tree11Likes

Code::blocks 'undefined reference' error

This is a discussion on Code::blocks 'undefined reference' error within the General Discussions forums, part of the Community Boards category; The tutorial is garbage. Besides, I would recommend you get a C++ GUI framework such as Qt instead of doing ...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    The tutorial is garbage.
    Besides, I would recommend you get a C++ GUI framework such as Qt instead of doing pure Win32 programming. It's easier and it's faster.

    Some advice:
    - Don't use new when you don't need to. If you can away with not doing it, then do that. In this case, it's pointless.
    - Stay away from C functions. They are Evil™. wsprintf can cause buffer overflows. Learn to use stringstreams instead. You can get a C-style string from std::string by calling .c_str(). This allows you to pass it to certain APIs that require C-style strings.
    stahta01 likes this.
    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.

  2. #17
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,661
    The Forger is a better resource for WinAPI stuff at any rate, I managed to find links to it around here as well.

    I'll echo that you should use GUI framework if you need to make anything nontrivial (unless the WinAPI has some obscure feature that you need, but you would know better than me if that really was the case). Knowledge of the WinAPI isn't a hindrance, but it's not entirely necessary either. Carry on.
    stahta01 and Click_here like this.

  3. #18
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,343
    Quote Originally Posted by Elysia
    Don't use new when you don't need to
    Done - New removed.

    Quote Originally Posted by Elysia
    Stay away from C functions. They are Evil™.
    Saying things like that will make me disregard your other good advice :P

    Quote Originally Posted by Elysia
    Learn to use stringstreams instead
    As I said earlier, after I have finished the tutorial I will.

    Quote Originally Posted by Elysia
    wsprintf can cause buffer overflows.
    Can, but not always. Unless %s is used, I'm not going to worry about a buffer overflows -
    This appears in the WM_CHAR signal handler, so we know wParam is of a char datatype, so wsprint's output has a predictible length.

    This should be fine
    Code:
    wsprintf(w_str, "ch = %c", wParam);
    Quote Originally Posted by whiteflags
    The Forger is a better resource for WinAPI stuff at any rate
    That is an awesome link, whiteflags - Thanks a lot for that.
    Fact - Beethoven wrote his first symphony in C

  4. #19
    Registered User
    Join Date
    Oct 2006
    Posts
    2,351
    Quote Originally Posted by Click_here View Post
    Can, but not always.
    the fact that it can ever cause a buffer overrun is cause to never ever use it.

    Quote Originally Posted by Click_here View Post
    Unless %s is used, I'm not going to worry about a buffer overflows
    I suspect you simply cannot be convinced. make sure you let us know what publicly released software projects you end up working on some day, so that we can all avoid them.

    the simple fact is that if your tutorial is claiming to teach you C++, but it's telling you to use (w)sprintf and other C-style string handling functions, it's an awful tutorial. ditch it immediately. it is just simply wrong to use those functions in C++.
    Elysia and AndiPersti like this.
    Code:
    namespace life
    {
        const bool change = true;
    }

  5. #20
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,343
    the fact that it can ever cause a buffer overrun is cause to never ever use it.
    Look at the example I gave: The char array was declared large enough, so there is no way that that can cause a buffer overflow.

    make sure you let us know what publicly released software projects you end up working on some day, so that we can all avoid them.
    That's offensive - A clear personal attack that was uncalled for.
    Fact - Beethoven wrote his first symphony in C

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by Click_here View Post
    Look at the example I gave: The char array was declared large enough, so there is no way that that can cause a buffer overflow.
    The fact that it can produce a buffer overflow and that you do no checks to make sure it does not is enough to make it dangerous. Oversizing buffers is not a solution. It's a hack and a workaround.

    That's offensive - A clear personal attack that was uncalled for.
    I wouldn't take that as an offence. But it does bring a point home. If you continue to rely on unsafe C functions, your program will not be safe. We don't want that. So take it to heart and avoid them. Join the C++ community and transition to safer alternatives.
    Elkvis likes this.
    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.

  7. #22
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,217
    Join the C++ community and transition to safer alternatives.
    O_o

    And for that matter, transition to safer alternatives even if you stick with C.

    Soma

  8. #23
    Registered User
    Join Date
    Jun 2005
    Posts
    6,255
    Quote Originally Posted by Elkvis View Post
    the fact that it can ever cause a buffer overrun is cause to never ever use it.
    If you follow that logic fully, you will avoid using most of the C and C++ standard libraries.

    It is possible, accidentally or deliberately, to overrun a buffer with any function or operation that uses pointers, indices into arrays, indices into containers, or iterators.

    Even a simple function that is designed to be safe, like fgets(), can achieve a buffer overrun.
    Code:
        char buffer[5];
        fgets(buffer, 10, some_file_pointer)
    I think what you intended to say is "You should not use code constructs where the programmer cannot deliberately achieve ANY safe mode of operation".

    The wsprintf() %s format can be used safely, since the programmer can control length of both the buffer being written to and the string being written using %s. Admittedly, that means other constraints on those lengths need to be enforced separately. But, once those constraints are enforced, wsprintf() with the %s format is guaranteed safe (unless the implementation of wsprintf() does not conform with behaviour required by the standards).

    The (deprecated/removed) gets() function is one where the programmer has no means in code to achieve ANY safe mode of operation. That is, more or less, the reason gets() was deprecated and removed from the latest C standard.
    Right 98% of the time, and don't care about the other 3%.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 17
    Last Post: 07-08-2011, 07:11 AM
  2. Can't Compile a code!!! I ran into "undefined reference to" error.
    By andereasmehdi in forum Linux Programming
    Replies: 19
    Last Post: 06-28-2011, 05:45 AM
  3. gcc error, undefined reference
    By drshmoo in forum C Programming
    Replies: 2
    Last Post: 04-04-2011, 09:33 PM
  4. Undefined reference error
    By pshirishreddy in forum C Programming
    Replies: 11
    Last Post: 08-02-2009, 06:34 PM
  5. undefined reference error
    By gcctest in forum C Programming
    Replies: 3
    Last Post: 12-19-2008, 07:17 AM

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