Timeline for Is there any reason to use C++ instead of C, Perl, Python, etc.?
Current License: CC BY-SA 2.5
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 5, 2020 at 12:07 | comment | added | Ivor Denham-Dyson | " There is no case in which C++ is slower than C because you can always use the C way if it is faster (and you care).". True but someone one stack overflow will tell you to rather use STL. | |
| Apr 22, 2016 at 8:17 | comment | added | underscore_d |
@martinkunev Hmm, so I wonder whether a static array parameter enables anything functionally different from a C++ template using a T (&arr)[n] or std::array<T, n> - will have to research this one more, as there's not a lot of info out there. That makes sense about smart pointers, definitely a good example. If coding on an equal playing field, we wouldn't use exceptions, so none of the potential costs would be incurred... however I suspect you might be alluding to how, once 3rd-party libraries enter the picture, a lot of assumptions are at risk.
|
|
| Apr 22, 2016 at 7:39 | comment | added | martinkunev | @underscore_d The size of a static array parameter is known at compile time - I wasn't able to find a concrete example of an optimization this enables, but it was added for a reason. Exceptions enforce smart pointers in the sense that throwing an exception will leak memory, unless you use smart pointers or wrap all functions throwing exceptions (which kind of defeats the whole purpose). | |
| Apr 21, 2016 at 17:08 | comment | added | underscore_d |
@martinkunev My bad, I got restrict the wrong way around... guess that was wishful thinking about a norestrict keyword ;-) Yeah, C++ lacks that. The static array parameter is news to me; what kind of optimisations does it enable over an array by reference or std::array by ref/ptr, or even a ptr/ref + size argument? Can you give an example of a situation in which "exceptions enforce the use of smart pointers" as I've not seen the two together (yet) and am not clear on what you mean. Thanks
|
|
| Apr 21, 2016 at 16:52 | comment | added | martinkunev | @underscore_d restrict permits optimizations, based on a guarantee for non-aliasing; static array parameters let the compiler assume that a pointer argument is not NULL and that this pointer points to at least a given number of elements; the word "style" has several meanings and putting it out of context changes its meaning - I'm talking about how, for example, exceptions enforce the use of smart pointers. | |
| Apr 21, 2016 at 13:01 | comment | added | underscore_d |
@martinkunev restrict is used to make exclusions from aliasing optimisations, so how does that help make things faster? and what is a "static array parameter"? and how does "style" affect performance?
|
|
| Oct 30, 2015 at 19:30 | comment | added | martinkunev | @JackAidley - Except that C++ does not support restrict and static array parameters. And except that using C++-style in one place forces you to use it at other places. | |
| May 15, 2013 at 15:44 | comment | added | anon | There is no case in which C++ is slower than C because you can always use the C way if it is faster (and you care). | |
| Jul 25, 2011 at 12:44 | history | made wiki | Post Made Community Wiki by user32315 | ||
| Dec 22, 2010 at 14:59 | history | answered | David Thornley | CC BY-SA 2.5 |