- A "better" C++ - 3 Updates
- A quick C++11 initializer list question (for set) - 1 Update
- Deep copying - 1 Update
jacobnavia <jacob@jacob.remcomp.fr>: Aug 20 12:10AM +0200 Le 20/08/2015 00:00, Christopher Pisz a écrit : > debugging C macros is even more fun... Don't know. struct ITERATOR(DATA_TYPE) { Iterator it; VECTOR_TYPE *L; size_t index; unsigned timestamp; unsigned long Flags; DATA_TYPE *Current; DATA_TYPE ElementBuffer; int (*VectorReplace)(struct _Iterator *,void *data,int direction); }; Is that too much for you? Any error in the arguments (DATA_TYPE, whatever) will be reported clearly. |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Aug 19 11:48PM +0100 On 19/08/2015 14:49, Stefan Ram wrote: > did not yet know how to write exception-safe code or did not > care. And even today, C++ is slower than C in the »programming > language shootout« (the last time I looked it up). C++ is not slower than C in fact the opposite is true. /Flibble |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Aug 20 12:08AM +0100 On Wed, 19 Aug 2015 23:30:13 +0200 jacobnavia <jacob@jacob.remcomp.fr> wrote: [snip] > What is nice about C is that the risk of ambiguity is much reduced. C > is much easier to debug and very stable. > And please, there is no free lunch... C has its drawbacks too. It most certainly does. The main problem with using C macros in the way you appear to have done is that they are completely unhygienic. They both inject names into the user code, and accept names from the scope in which they execute. You have to resort to trying to write renaming conventions for macros by hand, but which in C is impossible to do in an automated way because (to the best of my knowledge) the C preprocessor offers no facilities to do so. Chris |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Aug 19 11:16PM +0100 > Because Coordinate does not have a inilizer list constructor and nor a > normal constructor Coordinate(int, int) it just sets the members to 2 > and 7 in that order. I am right? It's not (as someone suggested) a C assignment[1]. The {2, 7} is an initializer list, even though what you've written is an assignment. So what it is initialising? You assignment is, in fact, a call to a compiler-defined assignment operator Coordinate &Coordiante::operator=(const Coordinate &other); and the {2, 7} is being used to initialize the single parameter. The supplied opertaor simple does a member-wise assignment using = for each of the data members. Initializer lists (in this form) are a C++11 feature. [1] C99 has compound literals. Using them you'd write the above as c = (struct Coordinate){2, 7}; but C++ does not have compound literals. -- Ben. |
Juha Nieminen <nospam@thanks.invalid>: Aug 19 08:19AM > I realise that this was not intended as a c++ question, but I can't see > a way to do this in c++ because of the huge generality of the question Well, objects themselves are "deep-copied" by simply using their copy constructor or copy assignment. OTOH, if the object in question is managing some allocated data, then it depends on the class's specification. In general, in a well-designed C++ program, it's up to the class itself (rather than the calling code) whether it internally uses deep or shallow copying of any data it has allocated (or possibly something else, like copy-on-write). Of course nothing stops a class from offering that choice to the calling code as well, by providing a public member function for either method. (It could, for instance, use shallow copying by default, but offer a deepCopy() member function that deep-copies the data for the object in question if it's being currently shared among several objects.) --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment