×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    39

    Smile Naming convention for function that leaves 2 or more objects on the cleanup stack

    Hi!

    Does anybody know the naming rule for the function that leaves 2 or more objects on the cleanup stack?

    For example, I need a function that will create 2 HBufC objects and leaves them on the cleanup stack. Would it be right to name it like this:

    Code:
    void GiveSomeStuffLC2(HBufC*& aBuf1, HBufC*& aBuf2)
    {
    aBuf1 = HBufC::NewLC(0);
    aBuf2 = HBUfC::NewLC(0);
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: Naming convention for function that leaves 2 or more objects on the cleanup stack

    Quote Originally Posted by » Symbian OS guide » Essential idioms » Naming conventions
    An allocation or construction function which places data on the cleanup stack ends with ...LC()
    So it is not about how much data you leave on the stack but the fact that you are leaving the data there. However you need to make sure to document the method properly...

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    39

    Re: Naming convention for function that leaves 2 or more objects on the cleanup stack

    But Ii think it can be little confusing, if I will place this into library and end the name with single 'LC'.

    Thanks anyway!

  4. #4
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    364

    Re: Naming convention for function that leaves 2 or more objects on the cleanup stack

    The Best Way:

    void GiveSomeStuffLC2(TDesC& aBuf1, TDesC& aBuf2)
    {
    HBufC* Buf1 = HBufC::NewL(aBuf1.Length());
    HBufC* Buf2 = HBUfC::NewL(aBuf1.Length());
    //--------------------->
    // Do what ever her
    //---------------------->
    delete Buf1;
    delete Buf2;

    }

    Good lack.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    39

    Re: Naming convention for function that leaves 2 or more objects on the cleanup stack

    Hi mubx2000,

    The question was about naming convention, not about the way of code organizing. I'm sure to use the function that leaves 2 objects on the cleanup stack.

    Thanks,
    Sergey

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Naming convention for function that leaves 2 or more objects on the cleanup stack

    Quote Originally Posted by mubx2000
    The Best Way:

    void GiveSomeStuffLC2(TDesC& aBuf1, TDesC& aBuf2)
    {
    HBufC* Buf1 = HBufC::NewL(aBuf1.Length());
    HBufC* Buf2 = HBUfC::NewL(aBuf1.Length());
    //--------------------->
    // Do what ever her
    //---------------------->
    delete Buf1;
    delete Buf2;

    }

    Good lack.
    Yeah, this code really lacks of good parts. Possible leak of Buf1 and improper naming - not a single object pushed on the Cleanup Stack.

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Naming convention for function that leaves 2 or more objects on the cleanup stack

    Quote Originally Posted by payu.sergey
    I'm sure to use the function that leaves 2 objects on the cleanup stack.
    Although having CBlah *&aBlah parameters is perfectly valid, C++ methods have one return value in general.
    Anyway, the Symbian source uses LCC (or even LCCC) in this case.

  8. #8
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: Naming convention for function that leaves 2 or more objects on the cleanup stack

    Quote Originally Posted by wizard_hu_
    Anyway, the Symbian source uses LCC (or even LCCC) in this case.
    Let's hope that nobody has the idea of implementing such a method with a variable argument list. How would that one look like ?

    Leaving the joke aside, LC should be enough as long as you document the method. It tells that the method can leave and that if not some objects are left on the stack. As always it is up to the caller to know which objects and how many they are.

Similar Threads

  1. What is the cleanup stack?
    By Sandra82 in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2004-11-13, 20:32
  2. the usage of cleanup Stack
    By qiuhuimin in forum Symbian
    Replies: 2
    Last Post: 2004-08-18, 02:22
  3. cleanup stack - function that leave
    By fcobsb in forum Symbian
    Replies: 0
    Last Post: 2004-07-23, 22:30
  4. bluetooth ptp problem with cleanup stack
    By CTPELOK in forum Symbian
    Replies: 1
    Last Post: 2004-06-29, 04:03
  5. Series 60 documentation error regarding R classes, cleanup stack
    By rtillitt in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2002-12-06, 02:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×