pointer problem or so...

This is a discussion on pointer problem or so... within the C Programming forums, part of the General Programming Boards category; But then I would have to tab back 4 times instead of one to delete (or press space 4 times ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,461
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,457
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,457
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,474
    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*
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Page 2 of 2 FirstFirst 12
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

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