« first day (278 days earlier)      last day (4662 days later) » 

12:18 AM
Speaking of 400 LoC, my Lua stuff has 400 LoC too. In the header.
 
1:00 AM
Why the fuck is my bash_completion turned off.
 
 
2 hours later…
2:35 AM
Hi !
 
 
6 hours later…
8:58 AM
Morning
 
Hi
 
@DeadMG Take a look at re2c, it's a bit more flexible with regard to the interface.
 
9:27 AM
0
Q: Why compiler does not complain about accessing elements beyond the bounds of a dynamic array?

user570593I am defining an array of size 9. but when I access the array index 10 it is not giving any error. int main() { bool* isSeedPos = new bool[9]; isSeedPos[10] = true; } I expected to get a compiler error, because there is no array element isSeedPos[10] in my array. Why don't I get an error?

Ok what magic compilers are these that everyone keeps saying will detect this kind of error?
 
lol, 13 answers in 30 minutes
 
9:43 AM
@DeadMG can you explain what a canary array is? Google doesn't help :(
 
canary arrays
 
Wait, found something.
Buffer overflow protection refers to various techniques used during software development to enhance the security of executable programs by detecting buffer overflows on stack-allocated variables as they occur and preventing them from becoming serious security vulnerabilities. There have been several implementations of buffer overflow protection. This article deals with stack-based overflow; similar protections also exist against heap-based overflows, but they are implementation-specific. How it works Typically, buffer overflow protection modifies the organization of data in the stack ...
 
basically, they're arrays allocated before and after the intended array, initialized to a specific value
when the value changes, you know the buffer has been overrun
 
Is it possible, at runtime, to find out the size on the return type of a function in the call stack ?
 
How does this "read only" memory work that makes your program die if you try to write to it? Perhaps one could mark some memory surrounding the array as read-only...
 
9:47 AM
no
 
@KerrekSB checks are added at runtime.
 
@Kerrek: I believe that you can mark it as read-only in some OS APIs
 
Hm, isn't there some low-level thing, like DEP?
 
DEP is execute
 
> Canaries or canary words are known values that are placed between a buffer and control data on the stack to monitor buffer overflows. When the buffer overflows, the first data to be corrupted will be the canary, and a failed verification of the canary data is therefore an alert of an overflow, which can then be handled, for example, by invalidating the corrupted data.
 
9:48 AM
@DeadMG Yeah, it'd have to go though the OS I guess.
 
@KerrekSB I think it's only possible to mark pages as read-only/read-write/executable etc.
 
pages in memory have RWX bytes just like files
 
Yes, like DEP, just "don't write" rather than "don't execute"...
 
DEP is just the ability to turn off the X bit
 
Ahh
 
OK, so there: One page per array, surrounded by pages with ---.
 
VirtualProtect seems to be capable of operating on the sub-page level
oh, no, it can't
 
@DeadMG LOL the comments
Dear Sir

in my computer runing videos in wimdows media player how encrypt the same screen in vb.net

please kindley send us code
 
Interesting. It'd probably be terribly slow to allocate any sort of memory, but hey, safe.
 
9:50 AM
@kbok Why not create that tag? I'd vote for it
 
@KerrekSB That would only prevent overflows that go longer than one page..
@KerrekSB It existed before. It's been banned.
We don't want any questions that could have it.
 
I see. Re memory, yeah, of course, and you also can't prevent stuff like x[HUGE].
 
@KerrekSB There is an entire history behind this tag ;)
 
@Martinho: You can deal with overflows less than one page too, if you site the array right on a page boundary
 
But as long as you prevent disaster arising from an overrun, you don't care if the user trashes her program.
x[-HUGE]
 
9:52 AM
Only works on one direction though :)
 
Hm, nice idea: [-------][---****][-------]
 
true
but I think that overflow is much more likely than underflow
 
You can either protect against v[N] or v[-1].
 
very wasteful!
 
@DeadMG Definitely.
 
9:53 AM
so you could site the array at the back end of a page, mark the next page as read-only
 
I never saw anyone starting a loop from -1. But I saw people ending it on i <= N.
 
not very page efficient, though
unless you have const data to go in that page
 
It'd be a pain for automatic arrays, too
 
yeah
 
And those are like, the most dangerous.
 
9:54 AM
Allegedly stack corruptions are far worse than heap ones
Yes
 
Heap corruption is much harder to exploit.
 
of course, the easiest thing to do would be to just check array indices
:P
 
Hmm, does std::array have at()?
 
Yeah, you could just have two types: static_array<T>, checked at compile time, and dynamic_array<T>, lenght-prefixed and with .at().
 
vector is a dynamic array.
 
9:57 AM
dynamic_array is std::vector.
 
static_array is std::array.
 
@MartinhoFernandes No, I meant fixed-size.
@MartinhoFernandes Indeed. One base covered.
 
If you don't change the size, it'll be fixed.
 
9:58 AM
dynamic_array should be runtime_array, since it can be either automatic or dynamic.
 
Changing the size accidentally doesn't sound like something very common.
 
Maybe a container adapter on vector to disallow resizing.
 
@KerrekSB Automatic arrays can only use compile-time size.
C++ does not have VLAs, like C99.
 
Or just don't resize, dynamic arrays with fixed size isn't something very useful.
You can always use scoped_array or something.
 
@MartinhoFernandes So C++0x does have VLAs?
 
10:00 AM
No.
 
no, it doesn't
 
Thank god, no.
 
Ohh.. I thought C++0x incorporates all C99 changes.
 
No, why would it.
 
no, C++0x includes quite a few C99 compatibilities and suchlike things
 
10:01 AM
Just to keep the development of the two languages vaguely in sync? After all, the C library is part of the C++ standard.
 
no
C and C++ are such very different languages, I wouldn't want them to try
 
I suppose it'd be sending mixed signals, and would distract people from using containers.
 
std::array<T,N> a is so much cooler than T a[N].
It's just a pity that most noobs will still be learning the latter.
There should be a law that you must obtain a license to write a C++ book.
 
T a[N] is a construct of this language called "C/C++"
 
Yesterday I learned one more advantage of std::array. You can overload on arrays and pointers.
Not the greatest thing, but it's one more.
 
10:18 AM
> There's really no need for a code example, it will over complicate it.
 
lol
 
11:03 AM
Dammit, ideone is slow as hell.
I blame your compiler.
 
kinda hard to lex // comments when you don't get a new-line
 
As a workaround you could use getline and a istringstream, but, both the unformatted input functions and the noskipws should work.
Apparently it does in Linux with g++, as that ideone link proves.
Are you sure you're checking for \r\n?
 
I'm reading in character by character
\r\n still has a \n in it
and I'm breaking on the condition and looking at every character read in
 
Ok.
I now officially have no idea what's going on :(
 
well
right now, I'm thinking of just grabbing the Windows API and reading the file using that, they won't skip whitespace
 
11:13 AM
I've been going through the standard, and I can't find any distinction from newlines and other whitespace.
const ctype<charT>& ctype = use_facet<ctype<charT> >(is.getloc());
assert (ctype.is(ctype.space,'\n')!=0)
What's the result of this?
This is the criterion given in the standard.
The locale decides what's whitespace.
 
@DeadMG Will probably be 10 times faster too
or just memory map the file
 
I've been thinking about just reading the whole thing in via WinAPI
std::wcout << L" Newline is space: " << std::boolalpha << ctype.is(ctype.space,L'\n');
newline is space: true
 
All whitespace is space.
 
So, why are newlines skipped, then?
 
11:22 AM
Show the reading code.
I don't remember having problems with reading newlines from istream.
 
Me neither. Code is on the question.
 
ok
I tried to read the whole thing in by WinAPI, but I think it's not recognizing the file as Unicode, whoops
 
I though the WinAPI had support for Unicode via wchar_t.
 
it does, it's not recognizing the file as Unicode
 
> Oops! Your question couldn't be submitted because: It does not meet our quality standards.
What does that mean?
 
11:35 AM
It's crappy question.
Or the system so believes.
 
post the question content on pastebin or something
 
I added some more text and now it worked :)
 
@Fred: you have Java at hand? Can you test if \d\d matches this: ٤٢ ?
 
\d is [0-9], so I doubt it.
 
Can you test it?
Is \d = [0-9] or is \d = "digits"?
 
11:45 AM
\d is digit, but the implementation could match Unicode digits as well.
 
System.out.println("\\d\\d".matches("٤٢"));
false
 
Lousy Java.
 
It's not Java's fault, they "inherited" regexes from some other language/system.
By the way, JavaScript has built-in regex literals. How cool is that? :)
 
Well, .NET did too, and they "fixed" them.
@FredOverflow No double-escaping, yay!
 
fixed them how?
 
11:47 AM
Made them Unicode-aware.
 
Double escaping is awful. Yay for C++0x's raw strings!
 
x = re.compile(u'\d\d', re.U)
print x.match(u'٤٢') # <_sre.SRE_Match object at 0x01F35288>
 
What is that, Python?
 
print was the hint :)
 
11:48 AM
imo, regexes as strings is just dumb
they should have a functional api
 
@MartinhoFernandes I like the improved title, thanks.
 
It's a bit long, though :)
 
It's a bit of a mouthful, but it describes what you want much better.
I think.
 
11:51 AM
Maybe "regular expression" could be dropped.
The tag should be enough.
 
right
 
Dammit, I was about to suggest what @Bart did.
 
Don's idea is also pretty cool.
Wait, it's basically the same idea :)
 
With an implementation a bit more complicated, though.
 
Flanagan... didn't he write the Rhino book on JavaScript?
 
11:58 AM
No idea.
That's a .NET article.
 
Oh wait, that was David Flanagan. Maybe they're related?
 
Doubt that.
 
> My main point of focus at work lately has been promoting maintainable code.
That's a promising start for an article :)
 
I don't know who that guy is, I just found that article some time ago.
It's a weird interface to write "readable" regexes.
 
> A recurring theme brought up was how hard regular expressions are to deal with. Not necessarily creating them - you can do a lot by just knowing the basics - but dealing with them after they've been written. As they mentioned on the show, your source code ends up looking like a cartoon character swearing, which is the likely response you'll get from the poor maintenance developer that has to deal with it. Regular expressions are often referred to as a "write-only" language.
interesting
 
12:01 PM
Oh, great. I found a bunch of generated code that is being recognized as chinese.
Here's a snippet: 㲿砿汭瘠牥楳湯∽⸱∰攠据摯湩㵧產晴ㄭ∶㸿਍洼摯汥椠㵤䐢佇湉敤≺礠慥㵲㈢㄰∱渠浡㵥䐢佇湉敤≺攠
Stupid editor.
 
probably a UTF problem
 
Yeah, I figured. It's fixed now.
 
if x86 is little-endian
do I swap when I get 0xFFEF or 0xFEFF?
 
Do you read 16 bit words from an 8 bit array or something?
 
Little endian BOMs come as 0xFFEF.
 
12:06 PM
no, I've got a vector of wchar_t that I read in using WinAPI
 
So, you need to change endianness if you get 0xFEFF.
 
huh
apparently the reverse is actually 0xFFFE?
according to that, FEFF is little-endian, and FFFE is big-endian
 
No. That's not what it shows on my screen.
FF FE UTF-16, little endian
FE FF UTF-16, big endian
Off to lunch.
 
bye
 
12:27 PM
> Consider a situation where the expected match is not well-known, and very likely to change: screen scraping HTML.
Stopped reading.
Also, that comment removing habit of mods is starting to be annoying.
 
Is it possible to change the language of compiler error messages in VS2010 ?
 
yes, I the language all the time
 
@jalf lol
 
argh
I've nearly fixed up my lexer to be completely working in my trivial test cases
but the bitwise operators still elude my grasp
 
These templates instantiation errors in french really doesn't help.
 
12:34 PM
can't you use the error numbers to look up the english versions on msdn?
could also suggest on their uservoice that they make standard english messages available regardless of localization
 
@jalf I did that, it helps a little. Still annoying though
 
@kbok got a link? I might give it a vote or two
I've never used a localized VS, but the idea of localized error messages terrifies me
or did you mean you looked them up?
 
@jalf Yep.
I'll look for a way to un-localize the compiler messages, and post a suggestion if it's not possible.
> voir la référence à l'instanciation de la classe modèle 'boost::_mfi::dm<R,T>' en cours de compilation
 
shudders
 
Looks like google translate.
 
12:43 PM
well, even if the translation was good, it's still so counter-productive because it prevents you from getting anything useful by googling the error message
 
@jalf, been reading some of the answers you've been giving, wow, where do you get all this knowledge? That's impressive!! :)
 
yay, I lexed a small program
 
nice one :)
 
True. Plus, the fact that I understand french casual language doesn't mean I understand french C++ talk. Documentation and books in native languages are very rare.
 
@TonyTheTiger which answers?
and I dunno, from reading answers given by people who knew more than me, mainly ;)
 
12:48 PM
@jalf quite a few of them, I just opened your profile and started reading answers you'd given to questions randomly. Some nice one's, which I upvoted :)
I learnt something too
 
@jalf I also learned almost everything (useful) about C++ beyond the most basic syntactic constructions by just participating on SO and reading better people's answers
and now I'm a C++ Expert™
 
I don't claim to be a C++ expert, but all my C++ knowledge comes from SO and TC++PL.
 
I'm definitely not a C++ expert, though my knowledge is always expanding
 
Browsing SO for answers to questions you didn't have is great.
 
@DeadMG I think I got a lot of it from the gamedev.net forums, before SO launched. Since then... SO ;)
 
12:51 PM
honestly? I usually just wait for someone to disagree with me that I'm an expert
and it feels hollow when nothing happens
 
And making you feel hollow feels great :P
 
I'm definitely not a C++ expert. Period.
 
@TonyTheTiger I've got plenty of bad answers too. Luckily, people tend to notice them less, because they're not upvoted. ;)
 
lol
 
cpx
Hmm I don't know how it feels like to be c++ expert yet ;)
 
12:56 PM
I think I've learned more from bad answers than good answers
 
@jalf hahah
 
when you make a good answer, then it pretty much implies that, well, you already know the answer
when you make a bad answer, it gets downvoted and someone makes a better answer, and you learn something
 
Oh you mean, posting bad answers.
For a moment there I thought you were talking about reading bad answers.
 
well, you can do that too for the same effect
if you would have posted the bad answer
 
this is interesting
10
A: How does a C++ reference look, memory-wise?

jalf How does a C++ reference look, memory-wise? It doesn't. The C++ standard only says how it should behave, not how it should be implemented. In the general case, compilers usually implement references as pointers. But they generally have more information about what a reference may point to,...

 
1:03 PM
I wonder why I added the k variable in that example
 
I can be a Python Expert™.
 
rofl
 
It's on the question. I guess you just copied it.
 
just noticed that it's utterly redundant, I didn't even see that when reading it
 
oh
that'd explain it
 
1:05 PM
well that makes sense
I'm still concerned, about the size of my lexer though
it's only 630 characters
including output and main function
630 LoC, even
 
heh, aaaand I got a 'nice answer' badge for the answer ;)
thanks :D
 
I was incredibly surprised when you said 630 chars.
 
so I wonder, how are casts like static_cast implemented under the hood?
 
With goat blood and magic.
 
cause technically, the type is just a thing for the compiler, so in machine code, that really doesn't mean anything, no?
lol
 
1:09 PM
no, that's not true
when you have a float that is, say, 250 (approximately), then the float and int binary representations of 250 are different
the CPU normally has an instruction that will convert
 
oh i see
 
It can also call conversion ctors or operators.
 
ok, I did a little formatting, and now it's just 570 lines
 
That's cheating.
 
what happened to those double-digit KB run-time libraries used by flex, etc?
it's not cheating, the output function is more naturally expressed that way
 
1:12 PM
Sure, that's why you didn't express it naturally that way :P
 
lol
I didn't express it naturally that way because I didn't realize that VS could build it that way
but it actually can
 
Ok, so you didn't just reformat?
Reformatting usually involves changing only insignificant whitespace.
 
well, I did just reformat
I reformatted because VS allows you to input on multiple lines at once
so expressing it as
switch(...) {
case SOMETHING : do_something(L"SOMETHING"); break;
}
for any number of SOMETHINGs that have been enumerated is just a little copy and paste
 
Hah! That's exactly the kind of "cheating" I was referring to!
Putting more than one statement per line to get less LOC is cheating.
 
hey, the result is more maintainable than the original, because you can edit all the cases at the same time
besides, the output function shouldn't even be counted in the LoC, really
which, without output, sits at 483
 
1:18 PM
I don't like writing lexers by hand, there's always some weird corner case that borks everything.
 
It's just an FSM, what could go wrong?
> ?? | Makes the preceding item optional. Lazy, so the optional item is excluded in the match if possible. This construct is often excluded from documentation because of its limited use.
Just learned another way to make regexes even less readable :P
 
as if they need help
 
tests every available regex engine for this crazy thing
 
I don't know about others but Python regex engine has an extended mode, which allows you to comment the regex.
PCRE had that too, I think.
 
I think that's in ECMAScript.
Ok, this ?? thing works in ECMAScript. And it can be easily used as a noop! (if you can accept false positives).
Oh the horror.
 
1:25 PM
ECMAScript is already a horror
 
I'm talking about the ECMAScript regex flavor.
Which, in the universe of regexes, is not really more horrendous than others.
But, the language itself, I won't argue.
((((((((((a??)??)??)??)??)??)??)??)??)??)??a+ is equivalent to a+
 
oh what the hell
and here was me thinking that C++0x's nested lambdas looked WTF
[](){[](){[](){}();}();[](){[](){}();}();}();
damn semicolons interrupting a perfectly good stream of brackets
 
> Titanic is only good if you watch Inception right after.
This is brilliant.
 
Though I don't see how that would make Titanic any good.
 
I've never seen it
 
1:37 PM
> AMA REQUEST: someone that has convinced their friend that Inception is the sequel to Titanic
It's boring.
 
Well it starts with him washing up on shore.
 
Oh.
It makes sense.
 
But outside of that I don't see what else should connect the two.
 
1:49 PM
Inception is just a dying delusion experienced by the character of Titanic!
It all fits in!
> I want to store all of the variables into one massive "Parameters.h" file so that I can access them from anywhere in my application. Each sub-page has it's own source and header file.
One massive file.
Ugh.
 
Good way to create a "compile bottle neck"
"let me change this variable" - recompile the whole project.
 
And it took a while 13 minutes until someone suggested singleton.
 
@MartinhoFernandes Or was the Titanic just a dream?
 

« first day (278 days earlier)      last day (4662 days later) »