« first day (443 days earlier)      last day (4488 days later) » 

Xeo
2:00 AM
Since it's an implicitly defined one
 
Maybe that's what the warning is about?
 
Xeo
oO default init should leave the buffer as-is. Value init should zero it out
Anybody care to test that with GCC and Clang on linux or something?
 
$ ./free-test
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
compiled using -Wall -pedantic -O2 -std=c++0x
 
Xeo
hm
Now I'm stumped
 
I modified it slightly to get rid of the warning
#include <array>
#include <memory>
#include <iostream>

int main(int argc, char **argv){
typedef std::array<char,20> buf_type;
typedef std::shared_ptr<buf_type> shared_buf;

char buf[] = { 5, 5, 5, 5, 5,
3, 3, 3, 3, 3,
1, 1, 1, 1, 1,
7, 7, 7, 7, 7 };
buf_type* pbuf = new (buf) buf_type();

for(unsigned i=0; i < 20; ++i)
std::cout << (char)((*pbuf)[i] + 0x30) << ' ';
std::cout << std::endl;
return 0;
}
 
2:04 AM
Wait, GCC warns as well?
 
it warned when initializing buf, which was of type buf_type
free-test.cpp:12:21: warning: missing braces around initializer for ‘std::array<char, 20u>::value_type [20]’
$ g++ --version
g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
 
Xeo
Eh? You got an array too much in there when you got that warning
 
{{ ... }}
 
Xeo
buf_type buf = { ... };, not buf_type buf[] = { ... };
The former shouldn't trigger any warning
 
It does on GCC 4.5.
 
Xeo
2:07 AM
Wait
Still, why?
std::array is an aggregate type, as such can be initialized using { ... } only
I don't get why there is a warning
 
using the double-brace it stops complaining
(and still outputs a sequence of zeros)
 
@Xeo It's an old bug.
Fixed in 4.6
 
Xeo
Ah, k
I was seriously worried there
 
Ok, sent an email to work asking for a day off tomorrow.
 
lol
struct foo { int x; }; struct bar : foo {}; What is the type of &bar::x?
 
2:11 AM
@RMartinhoFernandes Is this a bar joke?
 
No, I'm serious.
 
I'd say it is int.
 
Xeo
int foo::*
 
No, int*.
 
Here's a tip: it's a pointer to member type.
 
2:11 AM
int *?
Damn.
 
@Xeo Yeah. It's not int bar::*. It's int foo::*. This sucks.
 
This is bullshit.
 
Xeo
No
There is a rationale for that
 
What is it?
FWIW, &bar::x is implicitly convertible to int bar::*.
But it screws my type deduction.
 
Xeo
lol
 
2:13 AM
@Xeo I'm sure there is. What I'm saying is that this rationale is probably bullshit.
 
I wanted to use &bar::x to deduce bar for another argument, but it deduces foo.
And everything goes bananas when that happens.
 
I think I have three different MSYS/MinGW installations right now.
 
I have 4.5, 4.6.1, 4.6.2, and a snapshot of 4.7.
 
Primary MinGW, one that Git tags along, and now Ruby DevKit.
 
Oh, then I probably also have the one from git.
Fuck.
Why does git pack that anyway?
 
2:17 AM
@Xeo: the rationale is that derived classes can shadow x?
 
How does that matter?
In that case &bar::x will give me the one from bar.
 
but it should work the other way round
yeah, exactly
 
But that doesn't justify it giving int foo::* for &bar::x.
It would still work if in my example it was int bar::*.
 
Xeo
> An object whose initializer is an empty set of parentheses, i.e., (), shall be value-initialized.
So far, so good
MSDN says that MSVC default initializes instead
To default-initialize an object of type T means:
— if T is a (possibly cv-qualified) class type (Clause 9), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);
— if T is an array type, each element is default-initialized;
— otherwise, no initialization is performed.
std::array would count as class type
 
@EtiennedeMartel I can only see "Etienne de" and I always think that it's followed by "Crecy". :D
 
Xeo
2:21 AM
Now let's see for the implicitly defined default constructors...
 
@Xeo Yes, but its default constructor will just do no initialization on each element.
 
@StackedCrooked Unfortunately, no, I'm not a DJ.
And I'm not French.
 
@EtiennedeMartel Well, at least you are an Etienne.
 
I'm so awesome.
 
2:23 AM
Right.
 
That was a little of topic.
 
Xeo
> The implicitly-defined default constructor performs the set of initializations of the class that would be performed by a user-written default constructor for that class with no ctor-initializer (12.6.2) and an empty compound-statement.
That should theoretically get MSVC to spit out a non-zero'd array
atleast according to its own warning
 
@StackedCrooked Nothing is off topic here.
 
PHP questions are.
 
@EtiennedeMartel No need to tell me :)
 
2:25 AM
Is that clear from the newbie hints?
 
Xeo
No questions about languages with dynamic typing or Java.
2
:P
 
I have a Perl question..
 
Oh you.
 
@Xeo Not a good idea to enumerate that.
 
I don't mind Python questions.
 
2:27 AM
@Xeo That excludes C# 4.
 
@Xeo What about Java?
 
Xeo
@RMartinhoFernandes Better?
@EtiennedeMartel Problem being? :P
 
It's a cool language.
 
Java is not dynamically typed.
 
Not entirely.
 
2:28 AM
And it also happens to suck.
 
@Xeo What about OCaml?
 
Xeo
Added
Can't edit any more. :(
 
OCaml should be no problem around here.
 
Or Haskell.
 
What about WideC?
 
Xeo
2:29 AM
So, can we get back to why MSVC zero-initializes the std::array?
 
Xeo
:(
 
aren't templates dynamic typing?
 
Xeo
Er, no?!
 
@Xeo Because it's got a bug in its own documented buggy implementation.
 
2:30 AM
@Pubby If you compile at runtime, yes.
 
@Pubby No. Templates are statically typed.
 
@Pubby They're about as static as you can get.
 
but the meta programs aren't type safe
 
Xeo
@StackedCrooked That kinda contradicts itself.
 
The types of expressions are determined entirely at compile-time, hence static.
@StackedCrooked Not even that.
@Pubby How so?
 
2:31 AM
@Xeo: maybe the point is that &X::y gets the type T Z::*, where Z is the shallowest class in the hierarchy which defines y, because there is no point on making object.*ptr = <...> illegal if object is instantiated from a class which derives from Z
 
There are a few simple types and typename.
 
typename accepts pretty much anything
 
Xeo
@RMartinhoFernandes and template for nested templates
 
@RMartinhoFernandes I just don't like to say no to somebody :(
 
Right, and that.
 
2:32 AM
@Pubby That's not what type-safe means.
 
@Pubby I think your definition of "type safe" is wrong.
 
@Pubby But nothing is determined dynamically.
The types of all expressions can be checked without running the meta program.
 
?
 
If you write std::vector<1> the compiler knows it's invalid without needing to instantiate std::vector.
 
but the expressions may not terminate
 
2:34 AM
Because the type of 1 can be determined statically (it's an int or something), and std::vector takes a typename.
 
yes, but that does not make it static typing
 
Yes it does! That's the definition of static typing!
The types are determined statically.
That's static typing.
 
@Pubby: what do you mean by "static typing"?
 
@Pubby Static typing means that type checking occurs at compile time. I think this is the case here.
 
2:35 AM
I think I will ask on SO
 
@Pubby: remember that the definition is about the type of the variables, not of the values
 
types are used as values in templates though :S
 
What?
 
@Pubby No, they're just types.
 
the type system is turing complete, right?
 
2:37 AM
What is the type of std::vector<int>::iterator? It's a typename.
 
typename tells nothing of the type
 
What is the type of typename std::vector<T>::iterator? It's a typename.
 
is javascript statically typed because everything type is a type?
 
@Pubby typename is a type in TMP.
@Pubby In JavaScript you can't know the type of an expression without running the program.
 
C++ is statically typed in entirety, including templates. All types are resolved at compilation time, all names are typed.
 
2:38 AM
same with tmp and the metaprogram
 
That's what makes it dynamically typed.
 
@Pubby: "static typing" means that, given a variable name, you can say what kind of values it holds at compile time
@Pubby: if you think C++ is dynamic typed, then name a counter-example
 
"dynamic typing" means you have to wait until runtime.
 
yes, but you cannot decide all types with templates
 
@Pubby No, you don't need to run the metaprogram to know the types in the metaprogram.
 
2:39 AM
What.
 
@Pubby Sure you can.
 
really need help(C# room is empty) anyone know how to fill DataGridViewComboBoxColumn? (visual studio)
 
@Pubby Do you need to run the std::vector<T> metaprogram (i.e. instantiate it) to know that typename std::vector<T>::iterator is a typename?
 
Also, lol at this name.
 
2:40 AM
but how is typename a type?
 
@Pubby typename is a keyword.
 
std::vector<T>::iterator is a type.
 
typename is the type of ordinary C++ types in a metaprogram.
 
@Srle Ask it on SO.
 
let me ask on SO and you guys can answer
 
2:41 AM
@Pubby: typename is a keyword which is useful to disambiguate things when you access member types of a templatized class
 
Both int and typename std::vector<T>::iterator are values of that type.
 
@Pubby We'll probably say the exact same thing as now.
 
I want definitive answer
 
@Etienne de thanks, and thanks to Cat on stupidles :D
 
@Pubby: I think you just should review very careful the definitions
 
2:42 AM
The answer is "C++ is statically typed".
That's iiiittttttt.
 
C++ has dynamic_cast though.
 
@StackedCrooked It's not the same thing.
It's a downcast.
 
@StackedCrooked And that is statically typed!
 
Xeo
C++ has static and dynamic types, to be fair
 
It's runtime-augmented static_cast.
 
2:43 AM
I mean, you state the type of every variable and every templatized type is determined at compile-time, so the question is a no-brainer
 
What's the type of dynamic_cast<foo*>(x);? Do you need to run the program to know it?
 
@Xeo Name the place where you have dynamic typing.
 
Xeo
base* p = new derived();
// static type of *p is base, dynamic type of *p is derived
I didn't say dynamic typing
just dynamic types
 
yeah, C++ supports polymorphism
 
Xeo
2:44 AM
The standard even talks about static and dynamic types
 
@Pubby: even Haskell is statically typed.
 
haskell isn't turing complete at compile time
(afaik)
 
what do you mean by "turing complete at compile time"?
 
@Pubby Well, yes it is :P
 
@RMartinhoFernandes ?
 
2:47 AM
@akappa not turing incomplete?
 
Haskell types and type classes are powerful enough to perform any kind of computation.
 
Also Template Haskell.
 
I was talking about the "compile time" part
 
3
A: Solve the eight queens problem at compile-time

R. Martinho FernandesI came up with a solution that uses the Haskell type system. I googled a bit for an existing solution to the problem at the value level, changed it a bit, and then lifted it to the type level. It took a lot of reinventing. I also had to enable a bunch of GHC extensions. First, since integers are...

 
I think he's talking about the fact that you can write a calculator using templates and cycles of compilations
 
2:48 AM
Bask in the ugliness.
 
mmh. So the point is that the type-system is turing complete. This has nothing to do with static or dynamic typing, though
 
@RMartinhoFernandes do you have example of something that can't compile?
 
@Pubby I don't understand.
Something that can't compile for some specific reason?
 
something where the compiler doesn't halt
like recursive templates in C++
 
Infinite recursion?
 
2:51 AM
yeah, with the type system
 
Xeo
@akappa, mind testing this code again?
#include <array>
#include <iostream>

int main(){
    typedef std::array<char,20> buf_type;

    char buf[] = { 5, 5, 5, 5, 5,
                   3, 3, 3, 3, 3,
                   1, 1, 1, 1, 1,
                   7, 7, 7, 7, 7 };
    void* p = &buf[0];
    buf_type* pbuf = new (p) buf_type;

    for(unsigned i=0; i < 20; ++i)
        std::cout << (char)((*pbuf)[i] + 0x30) << ' ';
}
 
@Pubby template<int i> struct s { enum { value = i, next = struct<i + 1>::value }; };
 
@StackedCrooked I meant with haskell ;)
 
You'll have to gimme a few minutes, I'm not really an expert with this thing :S
But I'll be stealing @Stacked's example.
 
@Xeo: no warnings with -Wall -pedantic. Output:
5 5 5 5 5 3 3 3 3 3 1 1 1 1 1 7 7 7 7 7
 
Xeo
2:52 AM
Okay
So the warning that MSVC default initializes is wrong and it actually does value initialize
Because with that code, I too get the same output with MSVC
 
@Pubby: but do you realize that the expressiveness of a type system has nothing to do with it being static or dynamic?
 
@RMartinhoFernandes I think this might compile in Haskell due to its laziness.
 
@StackedCrooked The type system is not lazy.
All types must be evaluated upon compilation.
 
Xeo
It would get complicated if that wasn't the case
 
All I need is to build an infinite list.
 
2:56 AM
@RMartinhoFernandes Taken out of context that would be a strange thing to say.
 
Evaluate ALL the types!
 
@StackedCrooked infinite lists are common in haskell
0
Q: Templates statically typed or dynamic?

PubbyC++ is considered statically typed. I understand that. I don't understand how that applies to templates. Here is a simple example of a type that cannot be determined at compile time: template <typename... t> struct foo { using type = typename foo<t..., t...>::type; }; foo<in...

 
Lol, and now we all vote to close his question.
 
Crush it!
 
:'(
 
3:00 AM
But x is not in the metaprogram!
 
There probably isn't too much activity on the site right now.
 
x is a variable whose type is the result of the metaprogram.
 
@RMartinhoFernandes ??
didn't I say that?
// type of x cannot be determined without running meta-program
 
@Pubby: that thing does not compile
 
But x is not at the meta-level.
@akappa It should hit the compiler limits.
 
3:03 AM
@akappa that's the point
 
Xeo
Pubby, you kinda sound like you just don't want to accept this.
 
@Pubby: nope, if something does not compile, then it does not make sense to talk about types and whatever
 
The compile-time of C++ includes the instantiation of templates. If you want to consider only the TMP subset, you cannot mix in non-TMP stuff, like x.
 
@akappa it compiles, just doesn't halt
 
@Pubby It does halt ..with an error.
 
3:06 AM
??
assuming implementation without nesting depth
 
It's valid C++. The fact that your puny compiler cannot eat it is not relevant :P
 
@bdonlan seems to be pretty knowledgeable.
 
bdonlan says templates are not statically typed, but the resulting program is
 
Woot! GHC just compiled my infinite list at the type level program!
I suspect I did something wrong.
 
what is the code?
 
3:12 AM
templates are turing complete (subject to running time limitations), and so one can rightly call the templates a meta-program, interpreted at compile time, which produces the concrete types used by the real program – bdonlan 1 min ago
 
Lemme post on ideone.
 
I think this pretty much answers your question
 
Xeo
0
Q: Is the C4345 warning of Visual Studio wrong?

XeoThe following code triggers C4345 on the marked line: #include <array> #include <iostream> int main(){ static unsigned const buf_size = 5; typedef std::array<char, buf_size> buf_type; char buf[] = { 5, 5, 5, 5, 5 }; void* p = &buf[0]; buf_type* pbuf = ...

 
@Xeo What do you want us to answer?
Oh, right, this isn't about support.
 
Xeo
I just wanted to dump it here. :)
 
3:12 AM
:D
 
Ah, it blows there.
As expected.
 
not familiar enough with haskell to understand it
 
It's not really something one needs to understand. It's not sane.
 
@Xeo I'm gonna upvote this shit.
 
@RMartinhoFernandes was your 8 queens code using church numerals?
 
3:17 AM
Hmm, what's Church numerals?
 
0 ≡ λf.λx. x
1 ≡ λf.λx. f x
2 ≡ λf.λx. f (f x)
3 ≡ λf.λx. f (f (f x))
 
Oh. That.
 
@Xeo I think the answer is yes.
 
Yes, I use a similar encoding, but with types.
 
3:19 AM
These numerals are made of pain.
 
Xeo
@StackedCrooked I'm almost certain the answer is yes.
 
@Pubby I think what I used is closer to Peano numbers.
 
@Xeo I feel tempted to post as an answer: "Yes.".
 
@StackedCrooked "templated"? Is that a pun?
 
No, it's distortion in my brains.
 
3:28 AM
Oh.
 
Xeo
@StackedCrooked Better than distortion in your pants.
 
That goes for anything.
 
Man, my flag weight has skyrocketed since I got to 10k.
And I'm always fascinated by the people who come on SO thinking it's a forum and post answers as if they were messages in a forum thread.
 
It's amazing how bad some people are at asking questions.
 
Yeah, like that question about C4345.
 
3:32 AM
Exactly.
 
Arggh, I hate the auto-removal of @notifications from comments. It makes me look like a silly teenager that has yet to learn the power of capitals.
 
Is there such thing as a non-silly teenager?
 
Xeo
heh
 
@EtiennedeMartel Yes. Me as a teenager.
 
Xeo
0
A: Is the C4345 warning of Visual Studio wrong?

Gerald P. WrightHere is how I read the MS article http://msdn.microsoft.com/en-us/library/wewb47ee%28v=vs.80%29.aspx Under the old version of VS (your original syntax) - in this article, VS 2003 - a POD initialize would default initialize with 0s. Your code would support this. Under the new version of VS - in...

Completely twisted the meaning of default and value init
 
3:34 AM
if capitals are so powerful, that must mean FORTRAN is the most powerful language ever
 
@RMartinhoFernandes Ooooh. I see what you did there.
 
Today's good deed:
2
Q: g++ unicode variable name

anonI am trying to use unicode variable names in g++. It does not appear to work. Does g++ not support unicode variable names, ... or is there some subset of unicode (from which I'm not testing in). Thanks!

 
I'm now trying to convince bdonlan that his answer is wrong. I won't post an answer because his answer is almost perfect, it just needs to read "static" where it reads "dynamic". :P
 
@Xeo Let's downvote that!
 
Let's downvote all the answers!
 
3:36 AM
"We don't like the way you end your sentences, boy."
 
> I do add a disclaimer that it is very late here and I am tired, so this may all be babbling.
 
@RMartinhoFernandes Try to bribe him.
 
Xeo
Someone upvoted that answer...
 
I think two-phase lookup is key here.
 
Xeo
And I'm to tired to correct him.
 
3:37 AM
@RMartinhoFernandes I don't see how typename makes it type-safe. Isn't it just to make it possible to parse?
 
Oh, not that again.
 
@Pubby What's this obsession with type-safe? That's not the same as static typed.
 
I'm punching my desk. Raaaage!
 
@RMartinhoFernandes static typing checks for type errors at compile time, no?
 
@Pubby It's about the fact that T::foo could be a type or it could not be a type when the metaprogram is run. But the compiler must know what it is before running it.
 
3:41 AM
Determining if an identifier is a type is not related to type checking
 
@Pubby Type errors can occur at runtime in statically typed languages: dynamic_cast.
@Pubby It is when your language (TMP) operates on types.
 
So it uses static and dynamic typing? :S
 
Xeo
It uses static and dynamic types, not dynamic typing.
 
So why do people say C++ is static :S
 
dynamic_cast is statically typed. I gave an example earlier.
 
3:44 AM
it's both though, no?
 
@Pubby Because it is.
 
dynamic_cast can fail at compile time, or run time.
 
No, as an expression, the type of dynamic_cast is known at compile time
 
Good point, but what about templates?
 
bdonlan's answer wasn't good enough?
 
3:47 AM
@EtiennedeMartel It has one word wrong!
 
Fernandes disagrees with him
 
@Pubby Oh dear!
 
It is unsettling as the robot is usually right on these things.
 
I get the impression that you really want C++ to be dynamically typed.
 
Thanks, but please don't go taking my word like that. I've been wrong before :)
 
Xeo
3:49 AM
He's a buggy robot
 
1
A: Is the C4345 warning of Visual Studio wrong?

Gerald P. WrightHere is how I read the MS article http://msdn.microsoft.com/en-us/library/wewb47ee%28v=vs.80%29.aspx Under the old version of VS (your original syntax) - in this article, VS 2003 - a POD initialize would default initialize with 0s. Your code would support this. Under the new version of VS - in...

^ i fixed. :-)
 
Oh hey, one of the answers quotes the Standard. It has to be the good one.
 
@Pubby let me see if I can explain why I think your example is not a good one. foo<int>::type is the result of the foo metaprogram. Can we agree on that?
 
Yes
 
Ok. It's pretty obvious you can't know the result of the program without running it.
 
3:53 AM
Yeah
 
But that's what you're using to show a C++ metaprogram is not statically typed.
 
Xeo
@AlfPSteinbach So it's really only a warning that a newer version is now conforming?
If yes, that's a pretty shitty formulation of the warning.
 
@Xeo yes
 
@Xeo That sounds like one more silly warning to dump into @Alf's header.
 
i think it must already be there
lemme check
 
3:56 AM
@RMartinhoFernandes You cannot determine certain errors inside a metaprogram without running it, yes?
 
> WARNING!, we've fixed an earlier bug!
I'm really laughing out loud.
 
oh thanks, it isn't there!
 
I'm glad I don't have neighbors.
@Pubby Just like you can't inside a real program.
 
Xeo
> This warning reports a behavior change from the Visual C++ compiler that shipped in Visual Studio .NET
Well, reading it again now, it indeed says exactly that
But only on the MSDN page
 
@RMartinhoFernandes finding type errors at run time = dynamic typing??
 
Xeo
3:57 AM
And they specifically say 2003 in the code sample
 
@Pubby Not quite. Dynamic typing is what allows you to, for example, decide the return type of a function from user input.
 
Xeo
@Alf, please make that comment into an answer, just this one time... I want something to accept. :s
 
oh, sorry
 
but u can "upvote" the comment
 
Xeo
3:59 AM
I did already
 
@RMartinhoFernandes The definition says "A programming language is said to be dynamically typed when the majority of its type checking is performed at run-time", isn't that the same thing?
 
@Xeo "by design", eh?
 

« first day (443 days earlier)      last day (4488 days later) »