f



variant vs strict aliasing rules

Hello,

the implementation of something like boost variant, to switch types, will
call the destructor of one type, and then call in-place new of the other
type with the same memory. What is in the standard or how does variant have
to be implemented to avoid violation of the strict aliasing rule? Or in
other words, how does the compiler know not to reorder the in-place new
before the destructor call because the two cannot possibly alias?

Thanks for enlightenment!

Arno


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
arnoschoedl
7/6/2015 8:13:51 AM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

1 Replies
463 Views

Similar Articles

[PageSpeed] 1

On Monday, 6 July 2015 16:20:14 UTC+3, arnos...@googlemail.com  wrote:
> the implementation of something like boost variant, to switch types, will
> call the destructor of one type, and then call in-place new of the other
> type with the same memory. What is in the standard or how does variant
have
> to be implemented to avoid violation of the strict aliasing rule? Or in
> other words, how does the compiler know not to reorder the in-place new
> before the destructor call because the two cannot possibly alias?

Standard rather explicitly describes how the lifetimes of objects (and 
placement news and implicit calls to destructor) work in [basic.life].
 
Copy-paste of 3.8/4 ... :
A program may end the lifetime of any object by reusing the storage which
the object occupies or by explicitly calling the destructor for an object
of a class type with a non-trivial destructor. For an object of a class
type with a non-trivial destructor, the program is not required to call
the destructor explicitly before the storage which the object occupies
is reused or released; however, if there is no explicit call to the
destructor or if a delete-expression (5.3.5) is not used to release
the storage, the destructor shall not be implicitly called and any program
that depends on the side effects produced by the destructor has 
undefined behavior.

I do not see how strict aliasing rules have any power here to somehow
change the defined by standard behavior.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
ISO
7/6/2015 1:47:56 PM
Reply:

Similar Artilces:

strict aliasing rules in ISO C, someone understands them ?
I try to understand strict aliasing rules that are in the C Standard. As gcc applies these rules by default, I just want to be sure to understand fully this issue. For questions (1), (2) and (3), I think that the answers are all "yes", but I would be glad to have strong confirmation. About questions (4), (5) and (6), I really don't know. Please help ! ! ! -------- The Standard says ( http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf chapter 6.5 ): An object shall have its stored value accessed only by an lvalue expression that has one of the following types: - a t...

Strict aliasing rule: pointer to void vs. pointer to char and transitivity
Hi folks! My understanding of the aliasing rules is that a pointer to a char may alias any other pointer type. The following trivial example is therefore defined in C: static void printBytes(const char *bytes, size_t size) { size_t i; for(i = 0 ; i < size ; i++) { printf("byte [%zu] == %d\n", i, bytes[i]); } } .... const double foo = 42.0; printBytes((char*) &foo, sizeof(foo)); /* print bytes of foo */ However, when using a pointer to void to transition to a pointer to a char, is the aliasing rule still unviolated ? Ie. the foll...

C vs. C++ vs. Java
Hi! I'dont have any experiences in programming... what language should I start learning???? C? C++ or Java`? greetz Start with C go on to C++ and then on to JAVA. And you will C what how that helps. priyasmita_guha@yahoo.co.in wrote: > Start with C go on to C++ and then on to JAVA. > And you will C what how that helps. The OP's question is not topical to this group. It would be better answered in comp.programming among others. Please try to redirect off topic questions rather than answering them here. hi there! i think u sho0uld start wid C language and LET US C is an x...

Matlab vs C++ vs C#
Which of these should a person interested in financial modeling learn? "BB" <bb.donotmail@nomail.invalid> wrote in message news:ef1020b.-1@webx.raydaftYaTP... > Which of these should a person interested in financial modeling > learn? > If these are your only options, I would pick Matlab myself. You do much more with Matlab in much less time. Also debugging in Matlab is easy. Matlab also has a financial toolbox http://www.mathworks.com/access/helpdesk/help/toolbox/finance/finance.shtml Nasser Nasser Abbasi wrote: > > "BB" <bb.donotmai...

Cellular automata benchmarks: Java vs C++ vs Java vs C++
I love benchmarking. Here are some very interesting results which compare different cellular automata implementations in C++ and Java, with different versions of the Java VM: Sun vs Microsoft (MS). MCell is a Windoze C++ program, MJCell is MCell ported to Java, SARCASim is a 5++ year old C++ Windoze program of mine and my Modern Cellular Automata Java applet is rather unique. Because of restrictions in the size of MJCell's universes almost all benchmarks were performed using an 800 by 600 universe. All benchmarks were performed using the Brian's Brain three state cellular a...

floating point programming: c/c++ vs matlab vs fortran vs ???
Dear all, I am helping someone code a model of an optical amplifier in C code (with the aim of verifying results published by someone else). The model seems to behave correctly for a limited range of parameters, but is quite off outside this range. This is unacceptable; AFAICT theres no algorithmic reason the model should fail, so I suspect things are going wrong in floating point land. As I've been reading up on the matter I find there is a lot that could be going wrong: floating point exceptions, rounding errors etc. The model can be run reasonably quick, so we'd happily sacrifice ...

Fortran Vs C, C++, C#
What can Fortran do that C, C++, C# can't? Along similar lines where would Fortran be a superior chice over C, C+ +, or C# Jeff RF ENGINEER55 > What can Fortran do that C, C++, C# can't? > > Along similar lines where would Fortran be a superior chice over C, C+ > +, or C# None that I know of. Here is a dated (1992) paper comparing F77, F90, C and C++ for engineering pgrograms: http://www.leshatton.org/Documents/JSX_0192.pdf Me, myself and I, we all prefer C++. I like strong typing and mandatory function prototypes. I also like function overloa...

Android vs Qt vs C/C++
Hi All, I am a mobile application developer and this is the first time i have entered into developing an embedded application from scratch. I know that the title is a bit misleading and there will be rebuts in the grounds that Android is an OS and Qt is a framework and C/C++ is a language. Let me explain my requirement. I need to develop an embedded device which will be installed in a vehicle and it will periodically send telemetrics data to the cloud server using GSM modem. The telemetrics will include 1. GPS position data 2. Accelerometer readings 3. Image/Video data 4. It needs to li...

C++ vs C
I've just been working with a bit of C++ code for the first time (with a view to spending a couple of hours converting it to C. Or to *any* language that mere humans could understand, for that matter). But after that experience I don't think I'll ever complain about anything in C again! The thing was bristling with templates, specialisation templates, classes, namespaces, operators, friends, the full works, used, as far as I could see, just for the sake of it. (I managed to get rid of the templates, and it still worked..) This was a jpeg encoder/decoder, a comp...

C vs. C++
Hi everybody No trolling here, but I just thought C++ was just object oriented C but I was recently surprised to learn that C was much more used in numerical, computational physics. So here's my question : why would C be better for this kind of programming. beggars.banquet@gmail.com wrote: > Hi everybody > No trolling here, but I just thought C++ was just object oriented C > but I was recently surprised to learn that C was much more used in > numerical, computational physics. So here's my question : why would C > be better for this kind of programming. Physicists tend ...

C++ vs C
Hello, I'm writing an embedded application and I'm trying to decide whether to do it in C or C++. Does anyone know where I can find some statistic data comparing the two languages (size and performance)? Thanks, Nataly natush wrote: > Hello, > I'm writing an embedded application and I'm trying to decide whether to > do it in C or C++. Does anyone know where I can find some statistic > data comparing the two languages (size and performance)? > > Thanks, > Nataly Hi Nataly, I don't think that you can make a comparison between the two languages (in ...

C vs. C++
What is the main difference between C and C++. If I were to choose one to study so as to learn about game development which should I choose and why? Thx, R.Spinks R.Spinks wrote: > What is the main difference between C and C++. If I were to choose one to > study so as to learn about game development which should I choose and why? > > Thx, > > R.Spinks > > C++ is a superset of C, adding Object Oriented programming and Generics via templates. C++ is the main programming language of game developers, so it is very relevant to the industry. ...

C++ vs. C#
Very recently, I started a thread enquiring about the C++ object model. All that remains in my mind about that thread is: "why would you want to do that?", and "it's not portable" and probably other irrelevancy (read, no real answers). I spoke of "Lightweight" vs. "Heavyweight" objects. And of "representation in memory of an object" as important. Well guess what? I stumbled upon some C# description pages of structs, classes and the like. Guess what? What seems to be in this NG as "don't do that" and "non-portable", ...

obj-c vs c++ vc c
what are the differences between obj-c and c++? obj-c and c? i'm learning c at the moment, and i when i'm ready i want to take the "next step" to either c++ or obj-c, but i'm not sure which. jesse jesse wrote: > > i'm learning c at the moment, and i when i'm ready i want to take the "next > step" to either c++ or obj-c, but i'm not sure which. C++ is a lot more popular and so is more useful in the "real world". Objective-C is a very nice language but is poorly adopted. On the other hand, if you are working ...

Web resources about - variant vs strict aliasing rules - comp.lang.c++.moderated

Anti-aliasing filter - Wikipedia, the free encyclopedia
An anti-aliasing filter is a filter used before a signal sampler, to restrict the bandwidth of a signal to approximately satisfy the sampling ...

The Radeon HD 7970 Reprise: PCIe Bandwidth, Overclocking, & The State Of Anti-Aliasing
With the release of AMD’s Radeon HD 7970 it’s clear that AMD has once again regained the single-GPU performance crown. But while the 7970’s place ...

Fast Approximate Anti-Aliasing
Anti-aliasing has an intimidating name, but what it does for our computer displays is rather fundamental. Think of it this way a line has infinite ...

SWTOR's first major patch bringing bosses, anti-aliasing
... Wars: The Old Republic is getting its first major patch very soon, bringing fresh content and the long-awaited support for official anti-aliasing ...

Some Subtleties of Aliasing
Aliasing can cause paradoxical behavior.

Tessellation, ​Anti-Aliasing, And Other PC Graphics Terms, Explained
You've successfully made a new gaming PC. Congrats! It was the best, and it was also the worst. (But in general, it was the best.) Now, it's ...

How Anti-Aliasing Smooths Out Your Games, and Which Type to Use
If you've ever played a video game on your PC, you've probably seen a setting called "anti-aliasing", which smooths out jagged graphics. But ...

Email aliasing and spam
Great tip from Gabe Weatherhead. I didn’t know you could do this.

Am I the Only Person Left Who Hates Anti-Aliasing?
I'm not trying to pick on the New Republic here, but I'm curious about something. They launched a redesigned website yesterday, and here's how ...

New Nikon Patent Shows On/Off Switch for Anti-Aliasing Filter
... released its D800E and D7100, people were surprised to learn that these models did without the Optical Low Pass Filter (aka. the Anti-Aliasing ...

Resources last updated: 1/25/2016 11:56:56 AM