« first day (88 days earlier)      last day (4853 days later) » 

1:27 AM
0
A: comparing iterators from different containers

jweyrichIf you consider the C++0x draft: § 24.2.1 An iterator j is called reachable from an iterator i if and only if there is a finite sequence of applications of the expression ++i that makes i == j. If j is reachable from i, they refer to elements of the same sequence. § 24.2.5 The domain o...

 
1:42 AM
I hate memory growth.
A memory leak...I hate less. But a memory growth is difficult to track down. Valgrind is no help.
 
@Runcible oh, this can be easily solved. Please, donate all your new RAM to me.
 
:)
 
@Runcible massif or memprof maybe? Check the amount and size of allocations per function.
 
Hmm.. oh yes, I forgot about those tools. They are packaged in Valgrind, aren't they?
 
@Runcible massif certainly. MemProf nop.
 
1:48 AM
Ah ha. Ok, yes. This looks promising.
Thanks! =)
 
@Runcible you're welcome.
 
 
3 hours later…
5:02 AM
I don'T think that (char*)0 + 0 is UB
(char*)0 + 0 doesn't produce an overflow.
it says "If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined.". A NULL pointer doesn't point to any element and isn't a past the end pointer, so you have an implication "false -> x". this is always true, so the "otherwise" will never trigger.
 
 
2 hours later…
7:02 AM
@JohannesSchaublitb Are you sure about that? To me it reads if (same-array-condition) then well-defined else undefined-behavior, and since NULL does not point to an array, the condition is false, hence the else branch is taken which leads to undefined behavior.
 
7:29 AM
@JohannesSchaublitb I agree with @FredOverflow's parsing of that sentence. However, I still think the other later sentence applies so it is not undefined.
 
here's is a comparison: "If an expression is evaluated, the evaluation shall not result in overflow; otherwise behavior is undefined." does that mean that "sizeof foo()" is undefined behavior, because the expression "foo()" appears in an unevaluated operand?
 
Oh. You are saying the "otherwise" binds to "shall not overflow...," not to "if both..."
 
If so, that sentence sucks.
 
it doesn't say "Both the pointer operand and the result shall point to elements of the same aray object or one past the end"
"if foo; otherwise behavior is undefined." doesn't make any sense
so i don't think it should be interpreted as saying that
 
7:36 AM
Yeah, there's no shall in there.
 
tho i'm not a native speaker. so maybe there's some hidden trick
 
No; I think you are right.
 
i got some new shoes yesterday
nice gore-tex ones xD
 
applause
 
haha
i will test them now. let's see how they do when walking through water
 
7:40 AM
Does your office flood that often or is this a just-in-case thing?
 
so, here is a naive question. How does the statement:
int i = 1000;
result in defined (or undefined) behaviour, given that neither C nor C++ require int to be larger than char (or even require char to be larger or smaller than 8 bits)
 
I got new shoes over Christmas. They squeaked so I put baking powder in them. That stopped the squeaking but now I don't think I can wear them into an airport without getting arrested.
 
@James i tend to do a walk around in the mornings to get myself started
 
why wear shoes anyway
 
@JohannesSchaublitb Ah. Starting Tuesday I'm taking the bus to work and I'll have a bit of a walk to and from the bus stop. I think it'll be nice, at least on the four days a year that it doesn't rain.
 
7:54 AM
ohh
 
8:10 AM
@ChrisBecke No, but you can't have char being only 8 bits and int being no larger than char.
 
where is that a requirement?
 
int must be represented by at least 16 bits; that's specified in the C Standard (C99 5.2.4.2).
 
i mean, every compiler I know of has int as 16bits or more...
interesting
now that i actually look it up, section 5.2.4.2.1 of c99 deals with integer limits
 
even char has to be >=8 bits for a conforming implementation.
which means, i guess, that you could never make a c or c++ compiler for a ... theoretical cpu that addresses memory in 5 bit units for example
 
8:24 AM
Maybe. Perhaps you could write a virtualization layer that performed translation between C++ language concepts and 5-bit CPU concepts.
 
8:43 AM
i really don't anymore
im proficient in c++'98
a language I far prefer to c++03 or c++0x in many ways
life was so much more... <> free in the days before a standard stl, or ubiqutous exceptions.
 
@JamesMcNellis Presumably the ones who don't need to ask C++ questions.
 
im not saying a standard stl is a bad thing...
but i do find the evolution of c++'s syntax to be... heading deep into ugly
 
@ChrisBecke I'm much more comfortable in '03, I only know of one difference, though.
 
pre '03 boost was a dream, and the stl was really the (-s)tl, so naked pointers were the norm. and std::anything was never seen.
im pretty sure that up to '98 most compilers didnt even throw an exception if new failed. At least theres a lot of code from that time (And written by ppl from that time)
Bob* b = new Bob;
if(b){...
 
@ChrisBecke Aieee, I didn't realise that new returned NULL in C++98.
 
9:00 AM
I don't actually know if it did actually. I just know that it was common practice to test for null returns.
- one of the actually's
ah. here: http://support.microsoft.com/?kbid=167733
Visual Studio C++ 6.0 was documented as returning null if new failed to alloc memory
But the way its worded implies that even c++'98 required operator new to throw, and MSVC was simply non compliant.
 
sbi
@CharlesBailey It didn't.
What Chris is speaking about seems to be pre-standard C++. When each project had dozens of list classes, and even more string classes, used naked pointers (and suffered from the resulting leaks), code happily ignored return values which were used instead of exceptions, and Single Entry/Single Exit was looked at as if it was the holy grail. I'm not sure I view back on this as favorable as Chris does.
 
It wasn't all wine and roses.
 
sbi
@ChrisBecke VC6 came out in 1998, the year the standard was released, and was terribly outdated with respect to the standard, because by then MS hadn't attended standard meeting for so long they had lost their vote in the committee.
@ChrisBecke You must be British. Only a Brit could bring out an understatement looking so bloody serious.
 
but, Ive never belived that exceptions have been canonically proven to be the only true way to handle 'exceptions'. Making exceptions optional would have gona long way to making c++ a viable systems programming language. and a long way to... appeasing people who prefer the ... auditability of handling errors as they happen.
lol. my grandparents are mostly british
even the google c++ style guide recommends against using exceptions as an error handling mechanism.
the lack of standard runtime libraries in c++ was a huge impediment. Ive always felt that a lot of programmers jump ship to environments like C3, purely because doing anything in c++ has always been a case of starting everything from scratch.
c# even.
 
 
1 hour later…
sbi
10:22 AM
@ChrisBecke FWIW, I think google's C++ style guide is so bad, I believe it's a violation of the "Don't be evil" company motto.
5
 
sbi
10:40 AM
Haha!
in The SO Tavern (General), Jan 4 at 20:20, by Shog9
@JohannesSchaublitb We're creating a voting ring. It'll be unique in that we only down-vote, and only each others' posts. You in?
I've just come across this: stackoverflow.com/review. I suppose one needs to have 10k to see it, but I can't remember seeing it when I searched through the tools menu, and now I can't find any link leading to it. Does anyone here know where that comes from?
Oh, never mind.
in The SO Tavern (General), Dec 16 '10 at 9:03, by Jeff Atwood
please check out the new, experimental /review route, works on all sites
 
 
1 hour later…
11:56 AM
@sbi but bad in what way? I mean, 'badness' in a coding style would imply that it encourages developers to create code that is either incorrect, or hard to maintain.
c++ code that eschews exceptions is not, by definition, incorrect, and in some minds at least, is easier to visually inspect as the handling for error conditions is right there in the function. With an exception based error model, attempting to verify that an error condition is handled, during (for example) a code review, is that much harder.
exceptions require adherence to RAII, and RAII is just plain flawed in c++ because virtual methods dont work in constructors or destructors. Again, its almost impossible to see by inspection during a code review, that some ctor or dtor code path invokes a virtual.
 
@ChrisBecke That's backwards. With language support for ensuring that an error condition is handled, it's much easier to verify that it is. There's only way to see it as apparently harder, namely by mixing unrelated concerns. If so, fix that. Separate the concerns.
 
how does the language support 'ensuring that an error condition is handled' ?
 
@ChrisBecke "virtual methods don't work in constructors or destructors", that's totally incorrect. OK, you don't know what you talking about but you have strong opinions. Instead, try to learn: start by asking questions, like, "how do virtual methods work in constructors and destructors"
 
all it ensures is, sometimes, unexpectedly, exceptions will be thrown.
how can you argue that they work? given some
struct b { virtual void v()=0; b(){v();} ~b(){v();}};
class d : public b { virtual void v(){ ... };};
during b's ctor and dtor, the invocation of the virtual method v, will invoke the pure virtual handler
as d is not constructed at that time, do d's methods cannot be called.
 
"int* p = 0; cout << *p;" This demonstrates that pointers don't work.
You're at the start of the learning curve for C++.
The best way to learn is not to assert silly things, but to ask questions about how things work.
Now, how does exceptions ensure that error conditions are handled?
That's very simple: if an exception is not handled, then automatically std::terminate is called.
 
12:13 PM
thats just disingeneous. if a particular null pointer dereference fails, its usually quite easy to resolve.
 
Don't assert silly things.
Ask.
 
whereas, its very complicated in a non trivial class, to verify that a base class does not have ANY code path that can be invoked from its ctor and dtor, that does not call a virtual function
well, unless you throw out RIAA with the bath water and insist on trivial construction and destruction.
RAII damnit
thats not handling the error. thats just crashing
 
Also, you can expect that reasoning about things you don't understand will lead you astray (as above). Just ask about them.
FWIW, calling a virtual function from a constructor is not problematic in C++ (although it is problematic in Java and C#). Calling a pure virtual function from a constructor, is problematic.
 
@Chris: Sometimes, the only way to safely recover from an exception is to crash.
 
calling a virtual function is problematic too, as it violates the rule 'no suprises'.
the "wrong" virtual being called is a non obvious consequence.
 
sbi
12:19 PM
@AlfPSteinbach ...but only so from a constructor/destructor of the class that defines it as pure virtual, or of any class derived from it that's abstract because of (probably among others) this function. Phew.
 
agreed, sometimes the only way to safely recover from an exception is to crash.
 
sbi
@JohnDibling As the programming 101 professor of mine used to say: Better a clean crash than dirty mumbling on. (Or however to say this nicely in English.)
 
@sbi: I'm suprised a programming teacher said this. As I get older, I come more & more to the conclusion that professors are clueless.
 
sometimes its quite acceptable to continue on regardless.
 
@sbi Yeah, yeah. ï ï ï (double-dotted)
 
12:23 PM
point is. given the canonical example of "a program in charge of safety at a nuclear power plant"
its not obvious that between terminating, or continuing to operate in an undefined state, any one is worse (or better) than the other.
 
@Chris: you want redundant back up systems, including fail-safe restart
@Chris: and you want an audit log, because you want to analyze any bad behavior
 
Critical systems in the real world use hot redundancy, because software fails. Attempting to engineer a software system on the assumption that you can handle any error is naieve.
And dangerous.
 
@Chris: one of the first systems intended to be utterly fail-safe was original space shuttle system. three computers doing the same thing, voting on results. it's also interesting for later development process (which was very very formal); I don't think any of us would want to work that way, but it's how safety concerns affect things
@ChrisBecke I used to think that one should try to write code at level that other programmers could grok. I no longer think so in general, only for special cases. Dumbing down code to the level where incompetent can grok each individual statement, means the code as a whole becomes a lot less maintainable -- and it invites the imbecile to try to modify the code.
2
 
which all leads nowhere when deciding to throw, or not to throw :P
we agree, for critical systems, you can't depend on exceptions to make the system behave correctly, you need redundancy and other engineering practices.
and, for non critical systems. whether or not the system terminates, or continues to operate, is a matter of personal preference.
or at least, more better defined by the projects requirements
rather than some academics views on the theoretical purity of one error handling paradigm vs another
 
its not personal preference. it is always safer to crash than to continue with a munged heap. project requirements that state "handle every exception and continue" are broken
2
 
12:37 PM
on what basis? the correct project requirement is the one that inflicts the least economic harm on the projects implementors.
and that can go either way
 
@ChrisBecke I think John is talking about ethical behavior. Or an engineering perspective.
 
its unethical to not handle unhandled errors by terminating?
I say its unethical to waste your employers money
 
if your heap is munged, you're going to crash. it's just a question of when, and how.
 
@ChrisBecke Could be. It's like someone masquerading as a surgeon.
 
there are many errors outside of a munged heap
oh, stop it with the staw men alf.
software that continues to run after a file access failed is not 'masquerading as a surgeon'. we already covered the 'nuclear rod control software analogy'
 
12:43 PM
gotta go, i'll take this up later
 
it all depends on the nature of the failure, and the requirements of the project. terminate on error is not a one-size-fits-all solution
 
12:58 PM
@ChrisBecke right. i wonder if you're familiar with Meyer's Design By Contract (DBC)? It is of course not a one-size-fits-all solution either (or not even a solution to anything specific), but I find that it yields a very useful perspective on things. Helps to choose good solutions.
 
It sounds like something I should read.
still though I've yet to see any emperical evidence that favors either exceptions over error handling. Many statements of belief, by very smart people, so I have to give consideration to the idea that a lot of developers like, and prefer, exceptions.
Personally, I find code that makes extensive use of exceptions difficult to maintain.
In defense I have short term memory issues that make remembering a stack of c++ files containing implementation relevant to the function im looking at difficult.
So I do tend to prefer styles that encourage highly cohesive implementation.
 
1:16 PM
are we talking C++03 or C++0x?
 
c++'98 and up :)
 
because the transparent implementation is an advantage when used in generic code, as the less you have to forward between functions, the easier
especially if there are language-limitations on forwarding functions
how does std::for_each handle a failure by error code?
it can't
but by exception? it's easy- just don't catch anything
 
My mind just wondered, is "undefined behavior land" an amusement park? If so, would you visit it? What would the rides be called? :)
 
lol
The Null Pointer Dereferencing Wheel?
 
I guess my first stop would be "The Null Dereferencer".
There you go, lol.
 
1:19 PM
well, since c++98 the argument has been moot. language features have been designed around the expectation that exceptions are the canonical model for handling errors.
 
I think what's more important is that the language inherently supports error codes, by virtue of being able to return whatever you want
if I can return an int, I can return an error code, they don't need language support
 
as such, features like std::for_each can't handle errors via return code, because it was not a design consideration.
 
exceptions do, though
even if you did design std::for_each to handle error codes
how could you possibly?
 
i don't know
 
exactly
because, I believe, it can't be done
 
1:20 PM
there are lots of lanugages like lua that don't support exceptions
 
After that, "The Integer Overflow", a water ride where at the end, your cart is filled completely with water.
 
but do support iterators
 
Lua does support exceptions
 
to say it can't be implemented in c++ is to just be unimaginitive.
 
it may call throw error(), and try pcall(), but they are exceptions
 
1:21 PM
oh. my bad. really?
 
yes
 
lua excptions?
 
infact, if you compile the source as C++, then they will use C++ exceptions
if you compile it as C, they hack it with longjmp
 
i mean, lua the language, not lua the c/c++ library.
 
yes
 
1:22 PM
i dont belive that lua itself has an analoge of try/catch
 
throw = error
try/catch = pcall
 
pcall is how you interface lua with c? is there a lua keyword for creating a try/catch analog?
 
no
pcall is a Lua function
provided as Standard
so is error()
look them up in the Lua reference manual lua.org/manual/5.1/manual.html#pdf-pcall
"Lua code can explicitly generate an error by calling the error function. If you need to catch errors in Lua, you can use the pcall function."
 
oh ok. so the lua code
pcall(f());
essentially means:
try { f(); return true; } catch(int) {return false;}
 
effectively
but pcall also manages the return values and the value in the catch block
it's more like
 
1:27 PM
ok, well, I stand corrected.
 
unfortunately
Lua is a silly language
they should just have exceptions, it's not like pcall/error are different in any way
but they seem to pretend that they are really a C library and are not infact re-implementing C++'s features in a dynamic scripting language
 
a rose by any other name...
 
can't be bought and sold as one
consistency is important
 
still, pcall wrapping of for each type loops in lua doesn't seem common.
 
it's not
because they use exceptions and if the loop body throws, the loop iterator doesn't have to care
just like in C++, I don't have to protect std::for_each from my exceptions
also, I think there's an important language difference here
for example, you must throw from failed construction in C++
whereas in Lua, there are no constructors like that, you can just return nil
and let the access on the returned object fail and throw an error automatically
 
1:38 PM
the syntax of new and delete are, to me, the original sin of c++
 
@ChrisBecke Just ask, not assert. Like, "what does C++'s 'new' syntax achieve?"
 
I also think that it's wrong
new and delete exist because no perfect forwarding
in C++0x it can easily be std::new, just like std::make_shared
 
@ChrisBecke A book that's highly recommended by many: The Design and Evolution of C++, by Bjarne Stroustrup. Includes rationales for many things.
3
@DeadMG I think not so easily. The forwarding that new does is in the general case forwarding or a raw stack frame around a piece of code that handles exceptions. It's pretty difficult to do.
 
im sure theres a rationale
but
objective-c did the same thing. added object oriented extensions to C
in a far more elegant way
 
how is new T() different to new (malloc(sizeof(T)) T()?
fundamentally, not just std::bad_alloc and such
 
1:45 PM
ill grant that objective c syntax is ugly. c++: object.method(); vs obj-c: [object method];
but the managed to get construction, and allocation, down with the same syntax used for adding regular class methods, and static methods.
 
that doesn't really bother me
what bothers me is how unextensible new is
std::make_shared being an excellent example of the problem
 
well
 
@DeadMG new has to transparently deallocate if construction fails. in that case, it forwards original placement arguments to deallocation function. between allocation and final possible forwarding of placement args there's construction with forwarding of constructor args. difficult.
 
that is the core of my objection
objective c has an exensible syntax
c++ does not
 
@Alf: How is that not accomplishable as a regular function?
 
1:48 PM
in objective c, I can choose not to implement the dealloc (C++ delete) function, and instead implement a pair of retain and release methods
 
@DeadMG U can do it, but not very efficient. try it.
 
try and deprecate "delete" on a c++ object, and instead add a "release" operator.
so, objective C, with no changes to the base syntax or keywords, has been "upgraded" over time to - initially support direct allocation of objects, then reference counted, and now garbage collected
trying to implemente garbage collection in c++ is inconceivable without new keywords
or a lot of template cruft
 
the trouble with garbage collection is
it's much harder when you allow for garbage references to be on the heap
 
oh, im not saying i like garbage collection
 
native heap, I mean
 
1:51 PM
i do like the elegance of a language that managed to retrofit in optional garbage collection
with no changes to existing code
 
Hello from android
 
or reference counted objects.
I do a lot of windows development, hence a lot of COM exposure.
 
@ChrisBecke there are garbage collectors for c++98 (e.g. read up on Boehm garbage collector), and c++0x will support it more fully. so, again, assertion is silly. better ask.
 
so I am rather taken by the idea that c++ should have a way to deprecate "delete" in a class, and to add "retain" and "release" operators...
 
how is retain and release different to normal reference counting?
 
1:53 PM
Class a = new Class;
Class* b = retain a;
release a;
release b;
 
so it's shared_ptr, but written manually
 
which is a valid point. but the result is, ugly code
 
I agree, releasing and retaining manually is ugly
 
I can't read c++ with lots of explicit std::shared_ptr<blah> type stuff in it
it makes my eyes gloss over
 
Yep, manual release is ugly indeed.
 
1:55 PM
typedef ftw
 
indeed. but its still a lot of work
to get a feature the compiler should just implement for us
 
it does implement it for you
 
via some simple keywords
 
std::shared_ptr
why are keywords different to smart types?
except that destructor-based releasing is more reliable
 
Should, schmud.you can keep your damned garbage collection.I don't need your crutches
 
1:57 PM
IMO, it's not about crutches, I just like RAII and determinstic destruction
 
me too
 
I mean, let's say I implement a Text object
right now, I add it to the list of Text* in my render class on construction, remove it on destruction
then in the render loop, I can just loop through and render all of them
 
the difference? is that its possible to omit the smart types. Which is bad. They are mandatory. It is almost impossible to write correct c++ with explicit new's and deletes and raw pointers
 
but if I had to have garbage collection, then anyone who wanted to use the Text object would either have to leave it being rendered until it gets collected at some unknown date, which is bad, or remove it manually, which is also bad
so what?
 

« first day (88 days earlier)      last day (4853 days later) »