Re: [Dev-C++] Correct use of pointers
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: jo m. <non...@ho...> - 2003-03-14 19:58:07
|
Hello.
I don't see any problem with your example (except for the non-standard "void
main"). Tell me if I'm wrong:
A pointer in the stack is the same thing as an automatic variable in the
stack: it is released when you go out of scope, so no problem. Furthermore:
if you are concerned about eficiency, you shouldn't use the free store
unless you need it (for example when using dinamically allocated objects).
If you all don't aggree, please let me know. Thanks.
>From: André Macário Barros <and...@su...>
>To: "Dev-Cpp-Users" <dev...@li...>
>Subject: [Dev-C++] Correct use of pointers
>Date: Thu, 13 Mar 2003 21:46:02 -0300
>
>Gentlemen,
>
> Even in the Ritchie´s books sometimes I fount .C codes using "wild
>pointers" or something
>like:
>****************
>void main()
>{
> int *p, a, b;
>
> a=2;
> b=3;
> *p = a + b;
>
> ...
>}
>****************
>But... in large programs we can have problems.
>
> Would I be corret, allways, if I use insted a code like:
>*********************
>#include <stdlib.h> /* or alloc.h */
>
>void main()
>{
> int *p, a, b;
>
> p=malloc(1*sizeof(int));
> a=2;
> b=3;
> *p = a + b;
> ...
> free(p);
>}
>******************
>1. It´s not necessary, but is it tecnically correct?
>2. Is there any point, where the previous memory allocation is mandatory?
>
>Thanks
>Andre
>
>
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by:Crypto Challenge is now open!
>Get cracking and register here for some mind boggling fun and
>the chance of winning an Apple iPod:
>http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
|