« first day (421 days earlier)      last day (4527 days later) » 

7:21 AM
morning
 
Is there a way to break out of recursion prematurely? Similar to a break; in a loop?
 
@Joshua technically you can use an exception
 
Is there another way?
 
other than checking for "finished" everywhere, no
just document what you're doing
using an exception to break out of recursion is not bad in itself, but it flies in the face of the usual convention of failure = exception, so be sure to make clear what's going on
an extreme in the other direction, is that in python an ordinary for loop is terminated by a special exception...
 
7:36 AM
Alright thanks, I'll give it a shiot
shot* it's late.
 
or just return?
 
i think he wouldn't have asked if just returning was an option?
 
wtf recursive design doesn't end with "just don't call yourself again and return"?
 
8:01 AM
would a return type of a string array be string[] or string*?
I think string*
 
uh
I think that they're both completely wrong
you'd be looking for std::vector<std::string>
 
Well I have an array, not a vector
 
then that's a problem that you need to fix anyway
unless it's statically sized, I guess
in which case, yo could use std::array<std::string, size>
 
8:23 AM
Has anyone here read C++ GUI programming with Qt 4?
 
@Joshua listen to @deadmg, he knows about stuff
 
reshpeck
 
@Joshua string[] and string* are synonyms
actually not quite,
they indicate your intentions differently, but they behave the same
when used as a return type
 
yeah
they're both hideously unsafe and unusable for all practical purposes
 
ugh
@DeadMG then how are the standard library containers implemented if they are unusable for all practical purposes
 
8:39 AM
magic
 
seriously
there's no requirement whatsoever that they are even implemented in C++
 
Do you know of one where they are not
 
more importantly, just because the Standard library has to be implemented that way doesn't make it practical
the first C++ compilers had to be implemented in C, but I'm not stupid enough to think that's genuinely practical
 
But they are (usually), and they are perfectly safe
 
8:41 AM
when you only have things that suck, then you can only build things that don't suck from things that do suck
 
You could build things that suck from things that suck too
 
the only thing that makes them safe in the Standard library is because someone vastly smarter, and indeed, more powerful put in way more hours to make sure it worked
not re-using their effort is just stupid
 
So then pointers are useful and not unusable for all practical purposes
the standard lib is very practical
 
no, no, no
using the Standard library is very practical
implementing it, however, is most definitely not
which is effectively what you're doing by using pointers-as-arrays and such bullshittery
what's practical for a team of doctorates at Microsoft who only had to do it once is not practical for regular Joe users to do it all over their codebase
 
@DeadMG Just curious, but what else could you implement it with?
 
8:49 AM
meh, the Standard leaves it completely open
legally, you could run C++ in a VM and leave the Standard library as machine primitives
the implementation can do whatever the hell it wants in this regard, so use your imagination
 
But practically speaking, what could you do it with
noone's going to run C++ in a VM with machine primitives for the stdlib
 
that's another reason that doing it again yourself isn't so smart- the implementation doesn't have to conform to well-defined code, it only has to work on that target on that compiler version
 
there is a C++ interpreter, and I think that they do that
 
Why doesn't the implementation of the standard library (if written in C++) have to conform to well-defined code
 
8:51 AM
because it's the implementation
it can be specific
 
that makes sense I guess
 
when you're writing Visual Studio 2010, targetting x86, the Standard library only has to work on VS 2010 targetting x86 Windows
 
yeah
By the way, are you making your programming language public
 
a simple example is I/O
 
and also is it written in C++
 
8:51 AM
how do you think that's implemented? it's an OS routine call
but you could never portably replace it
 
I will do when I feel it's ready, and it is written in C++
 
It would be nice to look at the code, I could probably learn some stuff
 
many people could learn stuff from the code I write :P
 
What language is it most like
 
8:53 AM
C++
 
What's different about it
 
well, the syntax is way better, I cut a whole load of C's bullshit, and I introduced vastly more powerful templates
and it'll compile about a thousand times faster
 
Also this is a question I've had forever: If you write a compiled language or a JIT for a dynamic one, do you have to learn the assembly dialect for every platform the compiler/JIT will work on
 
strictly speaking, you do
however, you can use libraries that do it for you- like LLVM
that's what I'm doing
it's the only real choice unless you want to roll your own
 
user457812
Smart people get other people to do their work for them.
 
8:56 AM
what's that in reference to?
 
I'm doing everything by hand (except what the standard lib does) for my language, and it'd be cool to write a JIT for it eventually
 
ack
it'd be faster to use LLVM from the start
check out the Kaleidoscope tutorial
JITting it was simpler than writing an interpreter for it
 
Yeah, but I'm really just writing a language for practice
 
and LLVM produces very fast, very powerful code and is cross-platform
 
I'd use Lex/Yacc or whatever if I was seriously writing a language
 
8:59 AM
hahahahaha
no you wouldn't
have you actually seen the generated code?
 
it's disgusting and unusable
 
but yes I would because I don't know any better
 
nor did I but I did better anyway
 
You're not supposed to care about the generated code are you
 
9:00 AM
you have to
 
writing a parser that can recognize your language is cheap
writing a parser that can actually do useful shit in response to what it sees is hard
you can't use RAII or variables or anything in those table-driven state machines
 
What is the useful things you are talking about
ah
 
like building an AST, for example
 
Isn't that the very job of a parser?
 
9:01 AM
and they use char* all over the place, and global variables
anyone who cares about the quality of their codebase wouldn't go near them
 
that's good to know then
Knowledge +1
 
besides, it's less effort to write your own expression template-based lexing mechanism that's quick and easy and generates nice sexy code
 
I guess it would be more complicated for a compiled language
with lots of runtime constructs
 
nah
 
Well with an interpreted language almost everything is done at runtime
 
9:02 AM
the lex and parse stages are the same
 
so the complexity is moved from compile time to runtime
 
compiled vs interpreted is just a matter of swapping the code generation stage
 
from the parser to the interpreter
 
interpreters don't build ASTs
they execute ASTs
 
No, they run code
yeah
 
9:03 AM
you can't change the fact that your parser has to build an AST
 
With a compiled language, you have to keep information for everything to check all the compile-time stuff like type-safety, etc.
But with an interpreted language there is none of that
 
that's a separate stage to parsing
but interpreters still have to do it, just at run-time instead
 
I mean for the semantic analyser
yeah that's what I said, you move complexity from the analyser/parser to the interpreter
from compile time to runtime
 
no, just from the analyser
none is moved from the parser
 
9:06 AM
the parser does not give a flying monkeys about types
or if it's legal to pass 0 to a function expecting a std::vector<std::string>
 
Yeah I know
 
all it cares about is recognizing the input
 
@DeadMG have you ever messed around with the D language
 
it's pathetic
 
why do you think so
 
9:09 AM
they managed to identify some flaws in C++
then they didn't know wtf to do about it and made a bunch of stuff even worse
it means well, in some cases, but the fixes they designed and the implementation of it is incredibly bad
and then they broke a bunch of stuff that was just fine
 
I don't know it at all, I was just wondering if it would be a little like what you had in mind for yours
 
no
D is C#, but they added a little more power to templates- that's it
 
The templates of D are supposed to be more powerful anyway
yeah
 
they're not even remotely as powerful as mine are
the syntax still blows donkey balls
they utterly fucked their GC, value types, and reference types bullshit
and their compiler is slow as fucking hell
and my C++ interop is going to be much stronger than theirs
 
That's good
What types of things will your templates be able to do that is impossible now
with c++ or D
 
9:13 AM
everything
 
examples?
 
an example of "everything"?
just imagine something that can't be done in C++
 
Making coffee with a rock
 
don't think that's something that a program can do
 
You must have something that you can think of that your templates can do
 
9:15 AM
sure, the list is just a bit ridiculously long
first, templates can do anything run-time code can do
and second, they can perform introspection and mutation of all compile-time data structures, including types, functions, expressions, the works
 
So you can do stuff like read a file or download a file from the internet at compile time
 
yep
 
that's cool
Is the syntax for it easy
 
yes
way better than C++
 
user457812
It's easy like unicorn's blood
 
9:17 AM
Is it a curly-braces language
 
yes
I mostly re-used C++'s syntax, but I removed the ugly template syntax and swapped it for a much better syntax
also, to support many of the more complex compile-time computations, I swapped many places which used to be just identifiers, etc, for expressions
 
What do you mean
 
well, you can do things like
db_table := GetDatabase("mah_db").GetTable("mah_table")
db_table.GetColumnType("mah_column") item;
 
what does db_table.GetColumnType("mah_column") item; do
 
it defines a variable, item, with the type returned by db_table.GetColumnType("mah_column")
 
9:21 AM
Ah I see
Seems pretty cool, tell us when you release it :)
 
I will
if LLVM is as easy as the samples suggest it is, then it won't be long before I can JIT code
but it'll be a hassle because I'll have to write the Standard library from scratch
 
Haha, yeah
 
even IO involves memory managemet, strings, and of course, IO itself
 
Oh, it will be GC'd, yes?
 
not unless you actively request it
I actually have some special plans for GC
but it certainly won't be "YOU MUST USE GARBAGE COLLECTION TO SOLVE EVERY MEMORY PROBLEM"
the early versions won't have any GC at all
 
9:24 AM
yeah
 
LLVM ships with a GC but it doesn't meet my extensibility needs
 
I hear that the future of programming is functional languages
Do you think that's true
 
user457812
Who are you quoting on that?
 
whoever told you that was a moron
 
I'm not quoting it, sorry
 
user457812
9:25 AM
Well, if you ever quote someone on that, punch the person you quote
 
why would anyone use a language that offers functional programming, instead of a language that offers functional programming and object-orientated programming and dynamic programming and imperative programming?
 
Will do
I don't know
Haskell is purely functional right
or very close
 
user457812
Not exactly, if I remember right
 
It seems like with functional programming you go through huge contortions to do simple things
Anyway, I'm out
 
bb
 
9:47 AM
^^TRUE STORY^^
 
10:00 AM
when you open a file using std::ifstream without specifying a directory, it will look in the project dir by default right?
 
@IntermediateHacker )
 
@TonyTheLion It probably just falls back to the OS to do the lookup
 
hmmm
cause I have a ifstream which opens a .txt file, and reads from it. It used to work, but now it doesn't open it anymore
the file hasn't changed or moved
neither has the code that reads from it
weird
 
Morning
 
10:19 AM
morning
what's it called when you have myctor() = delete; ? The = delete; bit
or I've seen = default too
 
deleted or defaulted special member function
 
oh
what's the use of that?
 
@TonyTheLion I guess ifstream will look in the directory of your executable
 
yea that's what I thought
 
@TonyTheLion #1 use of = delete is making your classes noncopyable.
= default is useful when you implement a constructor with arguments, but want to keep the compiler-generated default constructor.
 
10:32 AM
@RMartinhoFernandes oh right
 
You can default any function that could be generated by the compiler. You can delete pretty much everything.
A deleted function participates in overload resolution (i.e. it may still be picked if it matches better than another), but provokes an error if it's selected.
void f(int) {}
void f(double) = delete;

f(1.0); // error!
 
Could you give an example when it's actually useful?
 
The standard library combines this with the almost useless const rvalue reference to prevent you from creating a reference_wrapper from an rvalue.
reference_wrapper<T> ref(T&);
reference_wrapper<T> ref(T const&&) = delete;
Normally, an rvalue can bind to a T& making a const reference. But since T const&& matches better, the deleted overload gets picked, and your code doesn't compile.
Or something like that.
I'm still waking up.
Ah, right. What am I saying? Rvalues can't bind to T&. Silly me.
Nevermind what I said above.
This is what the real thing looks like:
reference_wrapper(T&) noexcept;
reference_wrapper(T&&) = delete;    // do not bind to temporary objects
The problem here would be when the type of the wrapper is reference_wrapper<X const>.
Here T& would be X const& and that does indeed bind to rvalues. The deleted constructor with an rvalue reference matches better, gets picked, and prevents such code from compiling.
 
10:49 AM
user image
4
 
@Xeo: ooh, thanks for question votes :)
 
All arrays Chuck Norris declares are of infinite size, because Chuck Norris knows no bounds.
 
@DeadMG Because some people believe in purity for whatever reason.
 
@DeadMG because a language that focuses on one paradigm can do that cleaner, more robustly and likely more efficiently than one which tries to do everything
 
@DeadMG Oh, that's like decltype but without the decltype keyword, neat :)
 
11:02 AM
just use a browser for everything
 
Quite a few of the optimizations that make functional programs reasonably efficient rely on the absence of side effects and imperative code.
 
@SethCarnegie You cannot use int[] as a return type.
 
If:
S-> aBA
A -> r | t | ε

Should ε also be added to the follow set of B or should one look after A for extra characters?

Like:

S -> aBA3
A -> r | t | ε
FOLLOW(B) = {r, t, 3}
 
Can ε be in a FOLLOW set?
 
@AlfPSteinbach Personally, I like the technique of throwing an exception to break out of recursion. I think these are called "expections" sometimes :)
 
11:06 AM
I'm guessing it's the second one
That's what I'm not sure about
I don't think ε could be in a FIRST set either, except if it's of the rule
A -> r | ε
Then FIRST(A) = {r,ε}
But
S -> A2
A -> r | ε
Will give FIRST(S) = {r,2}
 
@BrunoAlano To set the second bit, use x |= 2. To clear it, use x &= ~2. To switch it, use x ^= 2. If you need something else, you have to be more precise ;)
 
@ManofOneWay Nope, ε cannot be in a FOLLOW set.
 
ε can be in FIRST if it's the only member in the set.
 
@Pubby You can use bitand instead of & if you want to obfuscate your code :)
 
11:09 AM
yeah, so A will have it, but not S
 
@KianMayne You don't need the if and the return true, just write return ceil(x) == x;
 
Hey there
howdy guys?
 
room topic changed to Lounge<C++>: Home of Asterisk and Obelisk [c++] [c++11] [c++-faq]
 
Who knows CMD syntax, please help. I have mini function shich deletes hidden files with .mta extension. Looks like that del /a:H /F /S *.mta
What I wanna do is, to delete both hidden and normal files. How to do it? Any suggestions?
 
11:16 AM
@DeadMG You don't need switch if you have pattern matching, because pattern matching is much more general than switch. Does your language have pattern matching?
 
@RMartinhoFernandes Do you think we can create a stackoverflow FAQ on Grammar operations? FIRST, FOLLOW, Ambiguous grammars, left-recursive, left-factored, creating DFA, symbol table and so on?
 
@FredOverflow My educated guesses: 1) yes, of course, but much better. 2) no, because pattern matching is stupid.
 
That said, pattern matching in boo is awesome.
Not saying that because I had a hand implementing it...
 
boobs?
 
11:19 AM
That was once the "boo build system".
 
Only 100 more C++ questions to 100.000!
 
Wrong! 99.
 
Did you just ask a question only to prove me wrong? :)
 
No.
Should I be insulted that you considered me capable of doing that?
3
Q: .template (dot-template) construction usage

mkostyaI've come across a strange segment of code: #include <iostream> template <int N> struct Collection { int data[N]; Collection() { for(int i = 0; i < N; ++i) { data[i] = 0; } }; void SetValue(int v) { for(int i = 0; i < N; ++i) { data[i] = v; ...

Please close as dupe of the FAQ.
Awesome how the FAQ was already suggested to me by the system! No need to search for it.
 
<mmintrin.h> for MMX
<xmmintrin.h> for SSE
<emmintrin.h> for SSE2
<pmmintrin.h> for SSE3
Do these names follow any system? Why x, e and p?
 
11:24 AM
eXtended? Extra? Powerful?
 
@FredOverflow I don't really think that it is
my only impression of pattern matching was that it was hideously unreliable
 
but if you're desperate for pattern matching, then the WideC switch is enough to support that
 
> SSE [...] is intended to fully supplant MMX
How can that be? SSE has nothing like saturated integer arithmetic, does it?
> SSE2 extends MMX instructions to operate on XMM registers, allowing the programmer to completely avoid the eight 64-bit MMX registers "aliased" on the original IA-32 floating point register stack.
Oh, I see.
 
What do you mean by saturated?
 
11:27 AM
250 + 10 = 255
 
Clamping instead of overflowing.
Uniform initialization is really sweet.
 
11:43 AM
@DeadMG What do you mean "unreliable"?
22
Q: Is continue considered bad style?

FredOverflowI feel myself tempted to write the following nested loop: for (int i = 0; i < N; ++i) { for (int k = 0; k < N; ++k) { if (i == k) continue; // ... other stuff ... } } Would this be acceptable, or should I use if (i != k) and thus introduce another level of nes...

> I don't think there's anything wrong, but i personally don't really use continue. I'm more bothered by the ++i and ++k than then continue.
lolwut?
Can anyone ask what's wrong with ++i and ++k? I don't want to register just for asking that.
 
well, that I thought it should match and it didn't
what happened to the "bin" room
 
@FredOverflow Done.
@DeadMG Move to the const room.
Dammit chat, where is the const room?
 
don't see a const room either
 
WTF, the bin is now a gallery room.
 
how irritating
 
11:56 AM
There's always the sandbox.
 
perhaps we should make a room between us that can become the new bin
1 message moved to Sandbox
well that's better
 

« first day (421 days earlier)      last day (4527 days later) »