Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Using TBuf as c++ std string

Started 2 months ago by StasV
Hello! I have such a function. Code: TBuf<50> Utils::LoadMessageL(int mesageId) { TBuf<50> text; text.Copy(_L("Some text")); return text; } Everything works just fine. But code scanner in carbide IDE tells me, that I am returning-descriptor-out-of-scope. Am I? Please, note, that Code: iUserManager->iUserLogin= iUserLogin; also works fine for me....
Site: Nokia Developer Discussion Boards  Nokia Developer Discussion Boards - site profile
Forum: General Symbian C++  General Symbian C++ - forum profile
Total authors: 3 authors
Total thread posts: 4 posts
Thread activity: no new posts during last week
Domain info for: nokia.com

Other posts in this thread:

laa-laa replied 2 months ago
No, you're returning a /copy/ of the TBuf that goes out of scope. It works but is not very efficient. It would be broken if the return type was either a pointer or reference to the out-of-scope stack-based buffer. If you need a function to return dynamic strings efficiently, either allocate them in the function (allocate and return an HBufC) or take in a target buffer (a TDes& function ...

StasV replied 2 months ago
No-error, but not efficiently - but highlighted like error. Thanks.

wizard_hu_ replied 2 months ago
If you read the description, it says that such code can panic on WINSCW, that is why it has "high" severity. TBuf-s are templates with some hacked size, that may be the reason if certain compilers find it difficult to copy properly.

 

Top contributing authors

Name
Posts
StasV
2
user's latest post:
Using TBuf<X> as c++ std...
Published (2009-10-28 10:06:00)
No-error, but not efficiently - but highlighted like error. Thanks.
laa-laa
1
user's latest post:
Using TBuf<X> as c++ std...
Published (2009-10-28 09:57:00)
No, you're returning a /copy/ of the TBuf that goes out of scope. It works but is not very efficient. It would be broken if the return type was either a pointer or reference to the out-of-scope stack-based buffer. If you need a function to return dynamic strings efficiently, either allocate them in the function (allocate and return an HBufC) or take in a target buffer (a TDes&amp; function parameter). Lauri
wizard_hu_
1
user's latest post:
Using TBuf<X> as c++ std...
Published (2009-10-28 14:59:00)
If you read the description, it says that such code can panic on WINSCW, that is why it has &quot;high&quot; severity. TBuf-s are templates with some hacked size, that may be the reason if certain compilers find it difficult to copy properly.

Related threads on "Nokia Developer Discussion Boards":

Related threads on other sites:

Thread profile page for "Using TBuf as c++ std string" on http://www.forum.nokia.com. This report page is a snippet summary view from a single thread "Using TBuf as c++ std string", located on the Message Board at http://www.forum.nokia.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity