Path: csiph.com!aioe.org!Hu1f/gStftKYRp2bwzXADg.user.46.165.242.75.POSTED!not-for-mail From: Meredith Montgomery Newsgroups: comp.lang.c Subject: on confusing procedure names with the address of procedures Date: Fri, 29 Oct 2021 21:37:48 -0300 Organization: Aioe.org NNTP Server Message-ID: <86bl37e49v.fsf@levado.to> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: gioia.aioe.org; logging-data="5122"; posting-host="Hu1f/gStftKYRp2bwzXADg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:aokKqOuql7EyVj+MZjaYr9kyOM4= Xref: csiph.com comp.lang.c:163260 I wrote --8<---------------cut here---------------start------------->8--- int main() { char c1; printf("c1 is at %p\n", &c1); printf("and the addr of the addr of c1 is at %p\n", &&c1); } --8<---------------cut here---------------end--------------->8--- and I didn't this to make any sense. Indeed, I get --8<---------------cut here---------------start------------->8--- %make nonsense gcc nonsense.c -o nonsense nonsense.c: In function 'main': nonsense.c:12:3: error: label 'c1' used but not defined 12 | printf("c1 is at %p\n", &&c1); | ^~~~~~ make: *** [: nonsense] Error 1 % --8<---------------cut here---------------end--------------->8--- The error message totally lost me. But then I wrote --8<---------------cut here---------------start------------->8--- #include int main() { printf("main is at %p\n", main); printf("main is at %p\n", &main); } --8<---------------cut here---------------end--------------->8--- and I expected a compilation error of some sort, but I got --8<---------------cut here---------------start------------->8--- %CFLAGS=-Wall make main-addr gcc -Wall main-addr.c -o main-addr %./main-addr.exe main is at 00007ff617431594 main is at 00007ff617431594 % --8<---------------cut here---------------end--------------->8--- So main must be stored at 00007ff617431594 and so it becomes unintuitive that getting the address of main yields the same value. My interpretation of this last program is that main = &main but for the first program &c1 =/= & &c1 because the right side is nonsensical? It's trying to get the address of an address, when we should only get the address of a name. Can't get the address of numbers. Pretty confusing.