Results 1 to 13 of 13

Thread: Use/Misuse of Pointers

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    91
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Re: Use/Misuse of Pointers

    aah..I got it now...dumb me..

    1. void fn(){
    2. int var1;
    3. {
    4. int var2;
    5. }
    6. // var2 is no longer valid here
    7. }
    and this is a neat operation, I had nearly forgotten about the block scope operator..thanx a lot wysota...

    I will definitely use pointers when I feel necessary..ther very point I was asking this question was because I get all these notions from my classmates who are afraid of the site of pointers....
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Use/Misuse of Pointers

    Quote Originally Posted by ct View Post
    and this is a neat operation, I had nearly forgotten about the block scope operator..thanx a lot wysota...
    Sure, but beware of the fact that this doesn't mean the variable is deallocated when it goes out of the inner scope. I'd assume it to be very compiler dependent, because the memory may be freed only when returning from the function, as this is done automatically by modifying the stack pointer in the CPU to reference the previous stack frame so no additional moves of the pointer are needed. So probably the memory is really freed when going out of inner scope on platforms that have a limited stack space. Otherwise it's just waste of CPU power, so the whole stack frame is probably freed in one go.

Similar Threads

  1. Pointer to a 2D array of pointers ??
    By aamer4yu in forum General Programming
    Replies: 2
    Last Post: 1st February 2007, 11:16
  2. Is it possible to store pointers in a database ?
    By probine in forum General Programming
    Replies: 8
    Last Post: 5th April 2006, 21:28
  3. another Q_OBJECT and pointers (?)
    By caminoix in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2006, 21:06
  4. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15:48
  5. K&R's strcpy function - problem with pointers
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 8th January 2006, 15:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.