Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #122699
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Equal yet different pointers |
| Date | 2017-11-16 16:14 +0100 |
| Organization | Informatimago |
| Message-ID | <m2mv3mfe7j.fsf@informatimago.com> (permalink) |
| References | <pointers-20171116105459@ram.dialup.fu-berlin.de> |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> I did not invent this program, I just read it in an article
> and then typed it in from my memory:
>
> main.c
>
> #include <stdio.h>
> #include <string.h>
>
> int main()
> { int i = 1; int j = 2;
> int * p = &i + 1; int * q = &j;
> if( !memcmp( &p, &q, sizeof( p )))
> { *p = 3; printf( "%d %d\n", *p, *q ); }}
>
> transcript
>
> 3 2
>
> NB: The memcmp compares the pointers themselves,
> not their pointees. p is only dereferenced after
> it has been established that it is memcmp-equal
> to q, which is a valid pointer.
>
Not here, but I have clang.
-*- mode: compilation; default-directory: "~/" -*-
Compilation started at Thu Nov 16 16:14:02
SRC="/Users/pjb/src/c/compare-pointers.c" ; EXE="compare-pointers" ; gcc -I. -L. -g3 -ggdb3 -o ${EXE} ${SRC} && ./${EXE} && echo status = $? ; cat $SRC ; gcc --version
different pointers
status = 0
#include <stdio.h>
#include <string.h>
int main() {
int i = 1; int j = 2;
int * p = &i + 1; int * q = &j;
if(!memcmp( &p, &q, sizeof( p ))){
*p = 3;
printf( "%d %d\n", *p, *q );
}else{
printf( "different pointers\n");
}}
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin17.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Compilation finished at Thu Nov 16 16:14:02
--
__Pascal J. Bourguignon
http://www.informatimago.com
Back to comp.lang.c | Previous | Next | Find similar
Re: Equal yet different pointers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2017-11-16 16:14 +0100
csiph-web