Thread: pointer problem or so...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    But then I would have to tab back 4 times instead of one to delete (or press space 4 times to ident) those spaces when you post the code somewhere.
    *sigh* We went through that in the other thread. You do not necessarily need to press backspace 4 times to delete an indent of 4 spaces, or press space 4 times to indent by 4 spaces. For some editors with the appropriate settings Shift + Tab may do the former while Tab may do the latter.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I mean browser. Not IDE. I remember that.
    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.

  3. #18
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by Elysia View Post
    You can remember that when doing char* str = "something" it's read-only - you can't change it or you'll get a crash. Therefore, it's better to use const char* str = "something" since the compiler won't allow you to change it then.
    If you're wondering why.
    It seems un-C like for the standard to say that string literals MUST be read-only.
    Does it?
    If it does not, then the reason to use const is to ENSURE that they are read-only.

    Oh, and on the tab/space issue, I'm a 4 spaces guy.

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    But you aren't allocating the memory for the string.
    The compiler must put that string somewhere and does so in a read-only section[1], so you can't modify it (you would get an access violation).
    So the strings SHOULD be const char* from the beginning! Why it actually allows char* is beyond me.

    [1] I believe this is compiler (and possibly OS) defined. Not 100% sure, but nevertheless, it's safer to use const char* to ensure it's portable.
    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.

  5. #20
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Why it actually allows char* is beyond me.
    Historical reason. Too much code was written before const existence that uses char* for that matter. The modern code should use const char*
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 08:53 PM
  2. Another pointer problem
    By mikahell in forum C++ Programming
    Replies: 21
    Last Post: 07-20-2006, 07:37 PM
  3. Pointer problem
    By mikahell in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2006, 10:21 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. pointer problem
    By DMaxJ in forum C Programming
    Replies: 4
    Last Post: 06-11-2003, 12:14 PM