Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(no subject)



Laurence Harris iwaku ~

On 11/27/03 12:24 PM, ai cui didst favor us with:

my code doesn't work well in Xcode:

int *p1;
int *p2;
*p=200; // EXC_BAD_ACCESS occur when debuging

So, is there a real POINTER data type in Carbon?

I am a fish, too. (Or was that a billy goat Gruff?)

Of course there's a pointer data type in Carbon. Did you consider what it's
pointing to?

Hmm.

int *p2 = (int *) "likely to be read-only garbage" ;

Nope. Bus error, just as it should. How about

int p2[] = { 'n', 'o', 't', ' ', 'g', 'a', 'r', 'b', 'a', 'g', 'e', 0 };

Or, we could do

int garbage;
int * not_garbage = &garbage;
* not_garbage = 200;
printf( "not_garbage now points at %d\n", garbage );

for a little variable-name-suddenly-ceases-to-reflect-program-semantics-at-run-time confusion.

Of course, there's always

int * p2 = malloc( sizeof * p2 );
* p2 = 200;
free( p2 );

and a reminder to never

free( not_garbage );

Why is it so weird when use it?

Because the love of money is the root of all evil.

Because you're writing sizeof(int) bytes out to a random location in memory.
You have to allocate storage to which the pointer points. This isn't an
XCode issue, it's a programming issue.

I don't know. I still think we are a fish.

(With apologies to the list.)
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.