Path: csiph.com!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!mit.eternal-september.org!.POSTED!not-for-mail From: Richard Newsgroups: comp.lang.c Subject: Re: pass by address Date: Mon, 05 May 2014 12:00:25 +0200 Organization: http://www.ieee.org/ Lines: 56 Message-ID: <87lhugv93a.fsf@gmail.com> References: <1phbm9t64tdkhq9pq5ng42v15s44tr01e0@4ax.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mit.eternal-september.org; posting-host="429d8c2c78b8d1bf0d1dfc93e35d17bc"; logging-data="5657"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pGfysfXtzJSHjfmg/gC3YhUDxe0FkSbo=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:E3XhPBcY+FhKHzK6SpmZgHmxAsY= sha1:KjuAeylTRCVVkhFWuzfMuoVMhJw= Xref: csiph.com comp.lang.c:44034 "Bill Cunningham" writes: > "Keith Thompson" wrote in message > news:lnr44aj596.fsf@nuthaus.mib.org... >> Tonton Th writes: >>> On 2014-05-04, Barry Schwarz wrote: >>>>>#include >>>>> >>>>>int main() >>>>>{ >>>>> int a = 15; >>>>> int *p; >>>>> p = &a; >>>>> printf("%p\n", &p); >>>> >>>> Undefined behavior #1. >>>> >>>>> printf("%p\n", p); >>>> >>>> Undefined behavior #2. >>>> >>>>> printf("%d\n", *p); >>>>>} >>> >>> I don't understand where in the undefined behaviour. Not so usable >>> values printed, yes, but &p and p are pointers, so %p can print their >>> values, no ? >>> >>> Maybe because p and &p are not 'void *' pointers... >> >> That's exactly it. "%p" requires an argument of type void*, not of any >> arbitrary pointer type. In practice, most implementations use the same >> representation and argument passing convention for all pointer types, so >> it's likely to work, but for well-defined behavior you need to cast the >> arguments to void*. > > Well I learned something today new. I'll keep that in mind. What would > be the best way to take careof that in your opinion? Cast a (void *). These > are the little things that you need to know so when you get into big > programs could cause real problems. > > Bill > lol! 10/10 "when you get into big programs" Genius! -- "Avoid hyperbole at all costs, its the most destructive argument on the planet" - Mark McIntyre in comp.lang.c