:: Re: [DNG] Making sense of C pointer…
Página Principal
Delete this message
Reply to this message
Autor: Steve Litt
Data:  
Para: dng
Assunto: Re: [DNG] Making sense of C pointer syntax.
On Mon, 28 Mar 2016 13:57:08 -0300
Emiliano Marini <emilianomarini82@???> wrote:

> char *p;
> p="01234"; /* skeezy, but makes the point */
>
> Warning! Here "p" is pointing to nowhere, you don't know which memory
> locations are writing to.


Yeah, that's why I said "skeezy". But on some of compilers, you can
actually strcpy(p, "43210") and you will neither get a compile time
error nor a runtime one, because when p is in scope, it points to 6
bytes *somewhere*, even if on the stack.

Also, if you *know* p will only be as an input and will not be changed,
my syntax is OK, although a #define would be better.

SteveT

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