Append Pointer To A String

Started by
22 comments, last by Nosaj 22 years ago
A POINTER CANNOT BE APPENDED TO A STRING the way you think it can.

a pointer is a datatype, like int or char, and all pointers are a standard, system-dependent length. pointers point somewhere.
when you say "copy pointer to string", i beleive what you mean is copy the data pointed to by pointer A, to a string.

when you declare a pointer,
char* str;

then you have an uninitialized datatype. the pointer ''points'' to a random location, like "int i", your pointer contains garbage.

when you say:
str = "asdad"; // same as str = &"asdad" 

you set the pointer, now it points somewhere special, a literal string . literal strings for the most part are reserved, or read only, so dont try to write to them.

char* str = "";strcat(str, "Asdasd"; 

this is an invalid operaton because str points to either a random spot, or to a reserved area. you cannot write to a reserved area, and, you cannot write to a random area, without getting undefined results.

in order to use functions that write to memory pointed to by pointers like str, then BOTH pointers must point to valid memory. otherwise, your making a logic error, and get undefined and often terminal results.
Advertisement
quote:Original post by Anonymous Poster
I dont know why you people even bother. Theres no point arguing with saberman, or even talking to him. If he says anything useful at all then he always throws in comments to act superior to everyone else in an attempt to reinforce his (much needed, apparently) perception of intellectual integrity.

Thankyou for contributing to the general hounding of me which has occurred this week. You have helped me to realise that my involvement in these forums is entirely free from value from my standpoint. There seems to be little interest in technical accuracy or correctness.
quote:
My favorite thing about sabermens posts are often the *vague* descriptions and solutions he provides. When people disagree with him, or supercede him, because he was vague, then he whips out the c++ standard, or starts with the personal attacks, or explains how he was correct in the first place (i especially enjoy those threads). Unlike beerhunter, you wont ever, in any thread, find him saying "oh, ok". instead he says "no... !!!".

Honestly, if he really was as smart as we'd all like everyone to be, then his first comments would have been, "thats illegal in accordace with the c++ standard", instead of letting people argue about valid program functonality. though, his last comments did make the savy switch from implied program functionality to clearly stated c++ standard compliance.

I suggest you take a look up at the first comment I posted to this thread, which says:

"This is still not quite right. There is no space "allocated" - even over-writing with a single byte would be illegal. He's actually pointed the string at an empty char literal, which does not belong to his program for manipulation."

That is a statement free from emotion, free from personal insult, and has basis only in fact. I'm not sure why you feel it was necessary to have mentioned "according to the C++ Standard" along with stating the behaviour is "illegal". I felt what I said stood-up on its own, I didn't see the need for all the extra baggage until I was contradicted. Also, read the ensuing post from mongrelprogrammer, and see if you can guess where the thread really turned into an argument.

Your complaint would carry more weight if I had argued for something which is demonstrably wrong.
quote:
gee, you would think that the smart people could end arguments quickly. But then, why would they argue about highly documented things in the first place?

Why would I need to quote chapter and verse of these highly documented things in the first place? For your information, I'm not interested in these arguments, I don't like arguing. However, I do value technical accuracy, and I am sometimes prepared to argue something I believe to be fact. Still, there is clearly no interest in facts or accuracy here, and I am clearly getting nothing from these arguments.

Finally, I'd like to recommend an article from Eric Raymond's FAQ collection: Smart Questions. There is an underlying philosophy that I like. You may or may not like it or agree with it, but it should be of interest nonetheless.

--
"Many people would sooner die than think. In fact they do."

[edited by - SabreMan on March 22, 2002 6:12:00 AM]
oh please.
yes, i was clearly talking about this singal thread, saberman, good deduction, good job, pat on the back to you -you solved the case, again.

blah haha

ive already been to that link, but thanks for providing it again.
i cant beleive you use it to justify your behavior, lol.
Enough!

If only people could seperate personality from principle and not feel the need to respond to their every criticism, these boards would be even more useful. If you''ve made your point and - as far as you''re concerned - the opposition is merely being pedantic, ignore them.

SabreMan, we''ve had this discussion in limited form and I generally agree that Standards-compliance and fundamental understanding are critical but in short supply, but I feel you should leave the ignorant to make their own mistakes where appropriate. I also feel you should refrain from bringing up credentials or any information external to the issue, such as who knows who or what. Principle, not personality. Thanks.

As for the rest of you, don''t always respond with indignation. It''s lame. Consider what SabreMan says, even if he''s "being a prick." Some of us have little use for frivolous niceties.

Thread closed.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

This topic is closed to new replies.

Advertisement