Skip navigation.
 
mlGCC not doing the correct thing?
FROM : Andrew Yager
DATE : Thu Nov 07 21:53:01 2002

Hi,

The following code snippet does not appear to function correctly.

#include <stdio.h>
#define cube(x) x*x*x

int main()
{
int x=1;
int y=2;
int z=3;
int* ptr = &z;

printf("%d\n", *ptr);
printf("%d\n", ptr);
printf("%d\n", cube(*ptr++));
printf("%d\n", *ptr);
printf("%d\n", ptr);


}

--

The preprocess code outputted from cpp is:

# 2 "test.c" 2 3


int main()
{
int x=1;
int y=2;
int z=3;
int* ptr = &z;

printf("%d\n", *ptr);
printf("%d\n", ptr);
printf("%d\n", *ptr++**ptr++**ptr++);
printf("%d\n", *ptr);
printf("%d\n", ptr);


}

However when compiled with łApple Computer, Inc. GCC version 1151, based on
gcc version 3.1 20020420 (prerelease),˛ the following is the output:

3
-1073742488
27
-1073742484
-1073742484

You can see on examination that this should not work... At least if it does
work, it shouldnąt work in this way...!!!!

Sorry for the uninformative error report... Someone with more skill at these
should perhaps do it...

Yours,
Andrew

___________________
Andrew Yager
Real World Technology Solutions
Real People, Real SolUtions (tm)
ph: (02) 9945 2567 fax: (02) 9945 2566
mob: 0405 15 2568
http://www.rwts.com.au/
_________________________


Related mailsAuthorDate
mlGCC not doing the correct thing? Andrew Yager Nov 7, 21:53
mlRe: GCC not doing the correct thing? Matthew Fahrenbach… Nov 7, 22:29
mlRe: GCC not doing the correct thing? Cameron Hayne Nov 7, 22:41
mlRe: GCC not doing the correct thing? Stéphane Sudre Nov 8, 02:35
mlRe: GCC not doing the correct thing? Richard Cleis Nov 8, 10:46
mlRe: GCC not doing the correct thing? Clark S. Cox III Nov 8, 10:53
mlRe: GCC not doing the correct thing? Richard Cleis Nov 8, 12:40
mlRe: GCC not doing the correct thing? Domain Administrat… Nov 8, 12:54
mlRe: GCC not doing the correct thing? Clark S. Cox III Nov 8, 13:08
mlRe: GCC not doing the correct thing? Nat! Nov 8, 20:23
mlRe: GCC not doing the correct thing? Andrew Yager Nov 8, 20:29
mlRe: GCC not doing the correct thing? Domain Administrat… Nov 9, 22:35
mlRe: GCC not doing the correct thing? Clark S. Cox III Nov 11, 07:13
mlRe: GCC not doing the correct thing? Thomas Castiglione Nov 11, 13:21
mlRe: GCC not doing the correct thing? Clark S. Cox III Nov 11, 15:21
mlRe: GCC not doing the correct thing? Keith Ray Nov 11, 15:43
mlRe: GCC not doing the correct thing? Clark S. Cox III Nov 11, 15:46
mlRe: GCC not doing the correct thing? Clark S. Cox III Nov 11, 16:12
mlRe: GCC not doing the correct thing? Cameron Hayne Nov 11, 23:31
mlRe: GCC not doing the correct thing? Thomas Castiglione Nov 12, 11:48