Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #70061

Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding

From James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups comp.lang.c++
Subject Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding
Date 2019-11-25 13:18 -0500
Organization A noiseless patient Spider
Message-ID <qrh5tl$aee$1@dont-email.me> (permalink)
References (9 earlier) <qr8jeg$v7n$1@dont-email.me> <qr8pu5$657$1@dont-email.me> <qr99qg$ats$1@dont-email.me> <qren31$fs3$1@dont-email.me> <qreqkn$51v$1@dont-email.me>

Show all headers | View raw


On 11/24/19 3:53 PM, Soviet_Mario wrote:
> On 24/11/2019 20:53, David Brown wrote:
...
> What's the effect of inline linkage ... 

C++ supports only three kinds of linkage: internal, external, or no
linkage (6.5p2). "inline" has it's own special rules, which interact
with the linkage rules, but it doesn't define a distinct kind of linkage.

> ... when one takes the 
> address of a function (and stores it)? I assumed, without> reading documentation supporting this, It would just ignore
> inline suggestion.
> Or is it undefinite behaviour ?

The term is "undefined behavior". Note, in particular, the American
spelling - US standards organizations played a disproportionate role in
the development of both the C and C++ standards.

Taking the address of an inlined function is not prohibited by any rule
of C++.

Any function may be inlined at the point of call (unless it has features
that prevent inlining), or it can have an actual function created for it
that gets called - that's true whether or not it's declared inline. If
you take the address of an inline function, and there's any possibility
that the function might be called through that pointer, that would be
one thing that might require an actual function to be created - without
preventing inlining of other calls to that function. Note also that if
the compiler can determine that the pointer is guaranteed to point at
this particular function at the time it is dereferenced, even that call
could be inlined.

The standard does say one thing about inline functions, linkage, and
pointers that might be of interest to you:'
"If a function or variable with external linkage is declared inline in
one translation unit, it shall be declared inline in all translation
units in which it appears; no diagnostic is required. An inline function
or variable with external linkage shall have the same address in all
translation units." (10.1.6p6)

That makes it quite clear that there's nothing wrong with taking the
address of such a function.

...
>> Or perhaps you think compilers add random padding and 
>> re-arrange structs in odd and unpredictable ways. 
...
> I'm not sure of the degree of freedom they have in 
> "reordering" members though.

"Non-static data members of a (non-union) class with the same access
control (Clause 14) are allocated so that later members have higher
addresses within a class object." (12.2p17).

Therefore, implementations have the freedom to reorder class members
only if you explicitly give them that freedom by using access control
specifiers.

> Sometimes in constructors I get some warning about the 
> members will be initializated in a different order than 
> declared.

That could happen through the use of access control specifiers.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding Soviet_Mario <SovietMario@CCCP.MIR> - 2019-11-24 21:53 +0100
  Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding Öö Tiib <ootiib@hot.ee> - 2019-11-24 13:46 -0800
    Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding Soviet_Mario <SovietMario@CCCP.MIR> - 2019-11-25 12:44 +0100
      Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding Öö Tiib <ootiib@hot.ee> - 2019-11-25 06:55 -0800
  Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-11-25 13:18 -0500
    Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding David Brown <david.brown@hesbynett.no> - 2019-11-26 08:22 +0100
      Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding Paavo Helde <myfirstname@osa.pri.ee> - 2019-11-26 10:19 +0200
        Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding David Brown <david.brown@hesbynett.no> - 2019-11-26 10:15 +0100
      Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-11-26 11:59 -0500

csiph-web