Nice surprise with C++11

Daniel Gutson daniel.gutson at tallertechnologies.com
Wed Aug 5 22:36:15 UTC 2015


On Fri, Jul 31, 2015 at 9:56 AM, Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
>
>
> On 31/07/15 14:51, Daniel Gutson wrote:
>>
>>
>> > Is it possible to construct objects without an address via plain C++?
>>
>> Sorry I don't understand the question. Rephrase please?
>>
>> Global objects and objects of static storage duration don't take an
>> address.
>>
>
> This register asm variable has no address, since this is a real register.
> This, however, is not a problem:
>
> int *h(void)
> {
>     register int i;
>     return &i;
>
> }

The 'register' keyword is deprecated since C++11.
Additionally, C++ requires that all objects have unique addresses, that's why
struct X{};
sizeof(X) > 0

(and that's why the "empty ase class optimization" idiom exists).

Moreover, taking the address of an object prevents such object to
dwell in a register.

In your example, even in previous C++ versions, should prevent the
'register' hint to be honored,
thus returning a temporal address to the stack (which would be invalid
in the caller's context).

So the short answer is NO.

Did I answer your question? Is there any case this should be possible?
(consider that I'm pursuing
new C++ features for embedded systems in the C++ committee).

   Daniel.

>
> --
> Sebastian Huber, embedded brains GmbH
>
> Address : Dornierstr. 4, D-82178 Puchheim, Germany
> Phone   : +49 89 189 47 41-16
> Fax     : +49 89 189 47 41-09
> E-Mail  : sebastian.huber at embedded-brains.de
> PGP     : Public key available on request.
>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
>



-- 

Daniel F. Gutson
Chief Engineering Officer, SPD

San Lorenzo 47, 3rd Floor, Office 5
Córdoba, Argentina

Phone:   +54 351 4217888 / +54 351 4218211
Skype:    dgutson
LinkedIn: http://ar.linkedin.com/in/danielgutson


More information about the devel mailing list