Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of standard-layout guarantees for "black box" types?

The C++ standard specifies that mutex, atomics or conditinal_variable are of standard-layout type.

What is the benefit of this specification? How a user can take advantage of this property?

And in general, what could I gain if a know a type is standard-layout without knowing the detail of its implementation?

like image 205
Oliv Avatar asked Sep 27 '17 13:09

Oliv


2 Answers

From this standard layout reference:

Standard layout types are useful for communicating with code written in other programming languages.

For example, if you build a mixed C and C++ application, the C structures will be standard layout and can be used interchangeably between the parts written in C and the parts written in C++. This is often very crucial for being able to use operating system native functions and structures.

like image 61
Some programmer dude Avatar answered Oct 31 '22 14:10

Some programmer dude


You could make your code talk with other programs, written in different Programming Languages than yours.

The ref mentions C++ concepts: StandardLayoutType:

Standard layout types are useful for communicating with code written in other programming languages.

like image 1
gsamaras Avatar answered Oct 31 '22 15:10

gsamaras