| Soviet_Mario <SovietMario@CCCP.MIR>: Nov 25 12:44PM +0100 On 24/11/2019 22:46, Öö Tiib wrote: > So removal of inline from non-template function when it is included > from multiple translation units leads to ODR violation and undefined > behavior. uhm ... I must admit I did not understand most. > There are no inline linkage. in general or in this case ? > Functions declared inline (or constexpr > that is implicitly inline) have external linkage by default. > The sole "benefit" we are guaranteed to get from inline is that we > may include same header that defines the inline function in multiple > translation units without violating ODR. I'm not sure : then Inline seems to grant the possibility of "redefinition" without redefining (as it is not considered a real function) ? Right ? I tend to embed some very short function in headers instead of a "pure" interface description and put ALL code in the .CPP unit. Is it a bad practice ? In case it is not a so bad habit : * I ought to add inline in all functions in the headers ? * It is a "must" only if I wish to include the same headers multiple times in different .CPP units ? (to avoid the redeclaration) ? * in headers I actually put "safeguard" like #ifndef THIS_HEADER #define THIS_HEADER ..... ..... .....
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment