:: Re: [DNG] Making sense of C pointer…
Startseite
Nachricht löschen
Nachricht beantworten
Autor: Steve Litt
Datum:  
To: dng
Betreff: Re: [DNG] Making sense of C pointer syntax.
On Thu, 31 Mar 2016 13:53:08 +0100
KatolaZ <katolaz@???> wrote:


> But be careful with statically initialised strings,
> since they are effectively constant char pointers (they are stored in
> the current stack frame, not in the heap, and the address stored in
> such variables cannot be modified, AFAIR).


This isn't exactly responsive to what you said, KatolaZ, but the worst
(and one of the most costly) programming mistakes I ever made was this:


=========================================================
char * read_bbs(){
char rtrn[WAY_BIGGER_THAN_EVER_NEEDED];
strcpy(rtrn, grab_bbs_part1());
strcat(rtrn, grab_bbs_part2());
return(rtrn);
}

result_string = read_bbs();
do_other_stuff();
use_result_string(result_string);
=========================================================

Well, it worked 99.6% of the time, but once in a while the whole
program blew up. :-). I solved this intermittent on my third visit,
racked up probably 10 hours trying to fix it, and my problem probably
cost a couple hundred hours of keypuncher time before I fixed it.

WAY_BIGGER_THAN_EVER_NEEDED really was way bigger than ever needed. Bad
programming, but that wasn't the problem.

All I can say is I *never* made that mistake again.

SteveT

Steve Litt
March 2016 featured book: Quit Joblessness: Start Your Own Business
http://www.troubleshooters.com/startbiz