Are you serious, const is in there.
Are you serious, const is in there.
Then either they forgot to change that example from really-old-C to old-C or they're just toying with you (or they mention in all the words around the example that they're doing something not-quite-right for illustrative purposes). I don't have the book so I don't know which.
In my experience, using gcc, a statement like
was always acceptable. Trying to do anything with this string, however, is nearly impossible and I can't think of a situation where having a string literal would be very useful in a program, except for using for comparison. Dynamically allocating space for a string and then using strcpy was always taught to me as a more standard practice.Code:char *p = "this is a string";
Hm, kinda stupid, the answer is just there:
"..pmessage is a pointer, initialized to point to a string constant; the pointer may subsequently be modified to point elsewhere..." (same page, my underlining)
There is no need for discussion on this topic really:
Originally Posted by C-99 6.7.8.32
With all due respect Andrew, you are missing the point. My question is not about changing the string literal (which causes undefined behaviour) but changing where the pointer points to. Anyway, as far as I am concerned,t he matter is resolved. I would like to know however, which of my code samples would have caused your compiler to warn.
Ok, all cleared up. I will reread this post carefully tomorrow and learn. Thanks again for the article about pointers, it seems I need to reread that too
I was trying to find a post I made a long time ago that modified the first argument to printf to print some stars or something, but I can't. It doesn't help that the search here sucks.
Edit: HAH! help with nested loops
Quzah.
Last edited by quzah; 08-08-2011 at 04:36 PM.
Hope is the first step on the road to disappointment.
For the record, I used to run an old version of LCC because it was all I knew at the time. It worked fine for years, but there are definitely some major issues and bugs I've come across. The most frustrating is how it seems to default the character data type to either unsigned or signed, depending on where the characters are declared (it appears to be unsigned by default in "main()" but signed by default in a custom function).
It works well for learning, but I'd recommend updating to something nicer. Though I haven't actually seen anyone here reference LCC, so I'd be interested in hearing if there were other opinions on it.