Your code. ANSI permits string constants to be read-only, and this is encouraged because it means they can be shared system-wide across all running instances of a program gcc does so unless you specify fwritable-strings while tcc makes them writable (probably because it's easier).
Your code. ANSI permits string constants to be read-only, and this is encouraged because it means they can be shared system-wide across all running instances of a program; gcc does so unless you specify -fwritable-strings, while tcc makes them writable (probably because it's easier).
Thanks. So I make it writable? I have to create an array of characters and link to that rather than a pointer to a string?
– Tnelsond Jun 4 at 19:09 @Tnelsond: you shouldn't rely on that behavior, and instead not initialize a char* from a const char (which degenerates in const char*). Use a copy instead. – rubenvb Jun 4 at 19:22 So I should use the strcpy function from a string literal to make a modifiable string?
– Tnelsond Jun 4 at 19:49 @tnelsond: Ideally, yes. C strings are... primitive. (Strings are the primary reason I stopped using C for much of anything.
Stick to C++ strings whenever possible. ) – geekosaur Jun 4 at 19:52.
Val is an points to read only location. Char *readOnly = "Data in read only location" ; readOnly pointing data cannot be modified.
As other answers have pointed out, val is pointing at a string constant. Try my_struct me = {4, malloc(2)}; and remember to check if val is NULL if you're using this in a real program.
Oh so that's how I'd do it. So I have to free malloced string afterwards right? Or will it free itself on exit from the program?
– Tnelsond Jun 4 at 19:15 @Tnelsond - You need to explicitly deallocate the resources using free. – Mahesh Jun 4 at 19:17 I need to free it even if my program is exiting? If that's the case, would it be better for me to just create an array of characters and link to that rather than allocating memory with malloc?
– Tnelsond Jun 4 at 19:22 @Tnelsnod you don't have to call free if your program is exiting, but you said you were giving us an example of code that was used in a more complicated program, in that case you should beware of possibly memory leaks if you don't free your memory. – sverre Jun 4 at 19:35.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.