Re: C++11 function late return value syntax.

[email protected] (David Oswald)
Newsgroups perl.inline
Message-ID <CAKTcQ96y+ddHa3Tx3Gfns-KBM_cYGp8XGM3rB-SzdxDqBW-xVg@mail.gmail.com>
On Mon, Sep 17, 2012 at 9:55 AM, Lou godio <[email protected]> wrote:
> Dave,
> Are  C++ inline functions (not intended for perl binding) OK ?
> Are there  any problems with malloc ( ) calls being used within C++ code ?


Let's talk about malloc first:

Are you writing C++ code that uses malloc, or are you using
Inline::CPP to handle C code?

If the latter, you can eliminate some complexity by working directly
with Inline::C, but should be using the Perl memory allocation macros
"Newx", "Newxc", or "Newxz" (see perlguts).

If you're actually writing C++ code, you should probably be using
C++'s "new".  'new' is the C++ way of allocating dynamic memory.  The
advantages to using it when writing true C++ code are numerous.  One
advantage is that 'new' ensures that your object's constructor gets
called (malloc doesn't handle this for you).  New is also type-safe
(malloc isn't).  And it can be overloaded for non-trivial classes
(malloc can't in any useful way).  Similarly, 'delete' (as opposed to
free) assures that destructors are called, and in the proper order.


As for inline functions; they are perfectly legal in Inline::CPP
whether or not they're intended for Perl binding.  There's even a set
of tests in grammar/t/03inline.t that verify they work as they should.
 The 'inline' keyword in specific will be honored to the same degree
that your compiler honors it (the compiler makes no guarantees; it
simply takes the request into consideration, and then does what it
wants).




-- 

David Oswald
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.