Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #122699
| Path | csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: Equal yet different pointers |
| Date | Thu, 16 Nov 2017 16:14:24 +0100 |
| Organization | Informatimago |
| Lines | 59 |
| Message-ID | <m2mv3mfe7j.fsf@informatimago.com> (permalink) |
| References | <pointers-20171116105459@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| X-Trace | individual.net BrU9Wjdzo0k136fSBdyBXwCBZ/NeAAdqgH6ro/ifMy37TmCYjQ |
| Cancel-Lock | sha1:NjEyNGY1NzIzN2E1MmM4OWI5ODczYzA2Y2JiMzMwOGU1OWMwNDY4Nw== sha1:7NOyvcW5DDjQn1bBv5oriMy/d7c= |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== |
| X-Accept-Language | fr, es, en |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/25.1 (darwin) |
| Xref | csiph.com comp.lang.c:122699 |
Show key headers only | View raw
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 | Unroll thread
Re: Equal yet different pointers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2017-11-16 16:14 +0100
csiph-web