« first day (237 days earlier)      last day (4704 days later) » 

12:05 AM
@DeadMG See the "HasCycles" function in this file: code.google.com/p/stacked-crooked/source/browse/trunk/…
 
@DeadMG sometimes I think your an actual dog.
A really clever one. That does C++
 
@DeadMG The argument "inPreviousNodes" must be passed as a value instead of by reference in order to make it work.
 
@StackedCrooked kk thanxx
 
@JohannesSchaublitb Heh?
 
@StackedCrooked: Why use that horrific macro when you could just use an inline function?
 
12:08 AM
@DeadMG That's so besides the point main. Btw, I wanted to be able to print file and line numbers :D
 
@StackedCrooked With shared_ptr elements your iterators are shared_ptr.
 
yeah, but you can get that by using the first-stage macro
you don't need the second-stage
 
I'm not even sure they are, let me double check
 
@LucDanton You could be right though. This tree-thingy isn't very well tested.
 
I think I read one line over the other or something actually
i.e. I read typedef typename PointerPolicy<This>::PointerType ChildPtr as a typedef for iterator, which is several lines down, so nevermind me
 
12:12 AM
@LucDanton no problem :D
 
Wouldn't having a std::vector<ValueType const*> remove the need for the const_cast?
 
@LucDanton Let me check it out.
@LucDanton you are very thorough :)
 
It's more that a const_cast triggers all kinds of red flags and alarm bells. Why did you put it here?
 
@LucDanton ok you can refresh now :)
@LucDanton I wouldn't have harmed since the values are only read and not written to. However, it could be avoided here.
And it's fixed :)
 
@StackedCrooked That's not true
const int i = 0; int& ref = const_cast<int&>(i); is UB even if you don't write to ref
 
12:21 AM
@LucDanton Hm.. I see.
 
The better reflex when the compiler finds a const violation is not to add const_cast, it's to add const and/or redesign.
You were possibly thinking of int i; int const& ref = i; const_cast<int&>(ref); which is indeed not UB.
 
@LucDanton I agree. Keep in mind though that this is very experimental code where I justed wanted to see if an idea of mine could work or not.
 
Funnily enough, you're doing std::find on a container of (potential) raw pointers!
 
My cycle detection probably isn't the most performant one :) But I glad I was able to make it work.
@LucDanton Is that also UB?
 
Internally it uses ==.
 
12:25 AM
@LucDanton Ok, so we're safe :D
Phew
 
I assume that operator== for boost::shared_ptr is fine, but for raw pointers it is not.
 
@LucDanton I thought only operator< was undefined on raw pointers...
 
int i, j; &i == &j; is just as much UB unfortunately.
It's the same rules: you can only relate pointers to elements of an array.
When the object are unrelated, you have to fall back on std::less
 
ah
that's not true, for ==
it's only for the relational operators
 
8
Q: Is it unspecified behavior to compare pointers to different arrays for equality?

Fred NurkThe equality operators have the semantic restrictions of relational operators on pointers: The == (equal to) and the != (not equal to) operators have the same semantic restrictions, conversions, and result type as the relational operators except for their lower precedence and truth-value resu...

 
12:27 AM
So it's possible to check for inclusion in a sequence, but in linear time?
 
These are all very shocking revelations for me. Stuff like std::find on a container of pointers is UB? What the hell!?
 
I'm irked that the Standard is inconsistent here!
Oh well it does make sense.
 
@StackedCrooked if std::find uses std::equal_to<> by default, I think that's fine, not UB or unspecified
 
@LucDanton It doesn't! Pointers are numbers. Numbers are comparable! Bad standard!
 
pointers are not numbers
 
12:39 AM
@JohannesSchaublitb How are they not numbers?
 
just like a map is not a bitset
even if in the underlying machine, it is represented as a sequence of bits
 
@StackedCrooked The classic counter-example is a segmented architecture, where pointers are e.g. a pair of numbers
 
they are never even a tuple of numbers
only on a different level of abstraction, pointers are numbers
 
I want to find a machine where "p1 < p2" doesn't work as expected.
Does that really exist.?
 
s/pointers/addresses/, I don't know what came over me.
 
12:42 AM
a compiler could optimize away such a comparison
int p1[1]; int p2[1]; p1 < p2 && p1 > p2 // compiler could yield true
 
@StackedCrooked Well x86 in real mode I assume.
 
@JohannesSchaublitb p1 < p2 && p1 > p2 can never be true
According to my sense of math and logic, that is
PHP is a different story
 
There are no pointers in math and logic
That's why there is a C++ Standard: to formalize things
 
Pointers allows for arithmetic like in order to support things like diff_type etc.. STL is also inspired on algebraic principles
 
And pointers to objects that are not in a single array are not defined to have an ordering
given int i; int* p = &i; there is no arithmetic to be done on p.
 
12:47 AM
Well, if that is what the standard say, so be it. But I can't make any sense of it.
 
you can only say p+0 and p+1
everything else is UB
 
There are two concepts : object handles, and iterators into an array.
It's a bit of a historical things that pointers implement both those concepts but they're quite different.
 
though int a = 0; int b = 0; if(&a + 1 == &b) { int *c = &a + 1 + 1; *(c-1) = 10; } assert(b == 10); is valid non-UB code
 
@JohannesSchaublitb std::find with three arguments is defined to use the == operator directly. However, pointers are equality-comparable, just not totally ordered.
Of course, you can explicitly pass std::less to an <algorithm> overload such as std::sort that would otherwise use builtin pointer < and get UB.
 
@Potatoswatter If pointers were not equally comparable, then I think that would pose a big problem..
 
12:51 AM
hmmmmmmmmmmmm
 
@JohannesSchaublitb I would not have expected &a + 1 + 1 to be meaningful
 
&a+2 is UB but &a+1+1 is not
if &a +1 == &b
 
And when is that last one guaranteed ?
Oh the if thing
 
@JohannesSchaublitb reference?
 
Heh I could see how you could try to crawl your way from objects to objects with that
 
12:53 AM
@Potatoswatter hold on, troll-usenet-discussion-link follows...
 
@JohannesSchaublitb Then you can just define a function: void Increment(T *& p, std::size_t count) { if (count == 0) return; p += 1; Increment(p, count - 1); }
 
@StackedCrooked But in your case you don't check that p + 1 is meaningful
 
/me looks through his 810 usenet posts...
 
In the example given by Johannes &a + 1 happen to be equal to &b.
 
@LucDanton this is based on @JohannesSchaublitb claim that &a+1 is valid
 
12:55 AM
Given that for int a[1];, a+1 is valid this is not inconsistent.
 
@JohannesSchaublitb You only have yourself to blame ;v) … we need to organize a litbopedia
 
@LucDanton And in his example above he defines a int *c pointing to an unused memory location on the stack, without invoking UB
 
givne int a; &a+1 is valid
and yields a pointer to the address sizeof(int) bytes past &a
 
Right.
 
so if there is an int object located there, &a+1 points-to that object
that's the very definition of "points to"
 
12:57 AM
Just as if a were int a[1]; (modulo syntax)
 
@JohannesSchaublitb Aren't you messing up the stack by doing this?
 
@StackedCrooked There is no stack; this is Standard C++!
 
I think you need to prove there's a specific reason why the user can't substitute 2 for 1+1
 
int a; *(&a + 1) = 10; foo(); // did foo just overwrite (&a + 1) ??
 
int i = *(&a+1) is UB in C, from what I know. but it is not necessarily UB in C++
 
12:58 AM
@StackedCrooked That's UB, the same way *container.end() = 10 is UB.
 
@LucDanton I believe that's not what @JohannesSchaublitb claims
 
@Potatoswatter the reason is that the standard forbits adding 2 to &a. but it does not forbid adding 1 to the address of b
 
@StackedCrooked He said the pointer is valid, not that you can write to it
 
(which &a + 1 + 1 ends up being)
 
… anyway, is there any way to reliably achieve b == a + 1 except that they both came from an array of at least two elements?
 
12:59 AM
no. that'S why I first tested it to be true with an if :)
 
… well, or part of a struct, but I think the same rules apply…
 
but you can do int c[2][1]; int &a = c[0][1]; int &b = c[1][0];
now a and b refer to elements of different arrays
 
> though int a = 0; int b = 0; if(&a + 1 == &b) { int *c = &a + 1 + 1; *(c-1) = 10; } assert(b == 10); is valid non-UB code
@LucDanton ^ Writing to c is not UB here?
 
It's writing to c-1.
 
@JohannesSchaublitb I thought a multidimensional array was still just one array, in address semantics at least
 
1:01 AM
Ah, ok.
 
@Potatoswatter in address semantics, all elements are contiguous
 
@Potatoswatter There are constaints on the size such that sizeof c == 4*sizeof *a but that's it
 
but in the language of course, there's N different arrays with N being the outer dimension's size
 
@LucDanton There is also a constraint on their order such that the last index "varies fastest" with respect to increasing address
 
@JohannesSchaublitb lol at usenet poster Seebs saying: "You are clearly crazy. "
 
1:04 AM
lulz
 
@Potatoswatter But that can be derived from the property of flat arrays, can't it?
 
@LucDanton It can't be derived simply from the property that sizeof( a[x][y][z] ) == sizeof a * x * y * z
 
@Potatoswatter So?
 
but §8.3.4/9, the text I was thinking of, is only an informative note. I'd like to think that array membership is transitive so address arithmetic between rows is defined behavior…
 
i'm not sure, but I would think that an element of one row is not an element of the whole table, in 2d-arrays-as-a-table-speak
 
1:12 AM
You need to invent some Clang optimizers that use this undefinedness to decimate offending basic blocks.
(I just read Lattner's recent blog posts :vP )
 
@Potatoswatter or for weather predictions
 
1:34 AM
@JohannesSchaublitb, I've always wondered why the standard algorithms use two separate overloads instead of one with a default argument. Now it turns out that this strategy can cause UB. Is there a rationale or a historical reason?
 
@Potatoswatter Default arguments can't be used for type deduction, can they?
 
… ah, right, no default arguments in function templates. Which is fixed now
@LucDanton I was thinking of a default template argument, which would produce the default function argument.
 
Now that's weird because I tried recently to deduce a template parameter from a default argument.
And I gave up on that.
And now if I just try...
 
they could still just forward from the 2-arg overload to the three-arg overload passing std::less<>
 
Oh right can't default parameter packs nevermind
 
1:47 AM
@JohannesSchaublitb That would be noncompliant… the 2-arg overload is defined to use operator< not less.
 
i mean, the spec can spec it
 
The user can explicitly specialize less to do something besides < for their types
 
ohh didnt know such
 
although when I brought up such asinine cases to Paolo Carlini at the the GCC stdlib, he seemed to think support for such isn't really important… so maybe it's not such a breaking change as to be a hindrance.
Don't quote me on that, I guess… lol
 
Holy shit it works!
@Potatoswatter It seems I owe you a whole lot
 
1:50 AM
@LucDanton note that it's C++0x-only
 
Well yeah.
 
@LucDanton LOL well if you're looking for a coworker…
 
Now how to know whether this is valid or not...
 
Where's the meta for chat? I want to suggest that ideone links should expand like images and wikipedia links
ok, it's just regular meta
0
Q: Can ideone.com links be previewed in chat?

PotatoswatterOften in programming discussion, we share code snippets with each other using sites like ideone.com or pastie.org. The chat already has cool previewing features that show the contents of a link of any image on any site, a Wikipedia article, a StackExchange question, etc. Can chat fetch and prev...

 
> A template type-parameter cannot be deduced from the type of a function default argument.
Welp, too bad.
 
2:01 AM
just add another overload
 
@Potatoswatter You don't owe me nothing
Yeah that's what I'm doing right now
 
@LucDanton Unless the compiler is willing to ignore a mismatch with the type of an unused default-argument, such deduction wouldn't get you anywhere anyway.
 
But out of curiosity I wanted to know if it's really possible to unpack a variadic tuple without delegating to another call.
 
showing the title of the paste, whether the code compiles and the language of the code would be helpful.
 
Anything that allowing such type mismatches could do, can be done with the new function template default argument facility.
 
2:03 AM
@Potatoswatter The idea is that I default a template parameter and let another get deduced from an associated default function parameter.
The type to be deduced being of the form indices<Indices...> where Indices is an int parameter pack.
The point is that I get to use e.g. std::get<Indices>(tuple)... inside the body.
 
@LucDanton Just copy the expression from the function parameter list to the template parameter list, put it inside decltype and make that the default template argument.
 
in c++0x, it's easy with lambdas and initializer list to execute something in order for every element of a pack
 
Have you seen what it takes to pass the contents of a tuple to a functor?
Not call the functor for each element.
But do f(std::get<Indices>(tuple)...)
 
template<typename ...T> void print(T &&...t) { initializer_list<int>{([t...]{ std::cout << t; }(), 0) ... }; }
this is a shorter form of "variadic printf" directly working with language support
 
Okay
Now do this but there's two tuples
 
2:07 AM
without format string but also without recursion! :) note that the order of printing is defined above.
 
I know I know I've done it.
It also works with {} syntax in general (how I solved it)
It's really weird, assuming a variadic constructor then the order for T(stuff...) is unspecified but for T{ stuff... } it is
 
But the problem I've been trying to solve is more similar to implementing that std::piecewise_construct contructor
Well not that one, it only takes two calls to std::forward_as_tuple but the one after
i.e. the constructor receives two tuples, now what?
 
@JohannesSchaublitb That is most awesome. Is initializer_list<int>{} the best way to throw out a sequence of ostream&, though? Those all get good() called and then the initializer_list object gets constructed, right?
 
i don't understand what you mean
i just applied operator, . didn't call good()
 
2:12 AM
Oh, I didn't see the , 0.
 
0
Q: C++0x use-case for piecewise_construct of pair and tuple?

towiIn N3059 I found the description of piecewise construction of pairs (and tuples). But I can not see when I should use it. I found discussions about emplace and non-copyable entities, but when I tried it out, I could not create a case where I need piecewiese_construct or could see a performance b...

 
one could also call .good or operator! or whatever of course. but the lambda returned "void". not "cout"
 
In that case, it's still constructing an initializer_list, right? Is that going to get no-op'ed?
 
It is possible to write a constructor that accepts two tuples like std::pair does and perfectly build the two members in place even if the types are not movable. But it takes delegating constructors.
 
i hope so
it's definitely allowed to :)
you could also create a struct slurp { slurp(...) { } }; or something and do slurp { ... } or such.
 
2:14 AM
Yeah, that does seem reasonable…
 
but it'S kinda ugly to do it that way IMO :)
 
Or template< typename r = void, typename ... t > r nop( t... ) {}
 
Mine was called expand. Then I realized I needed the , 0 trick and it became a macro EXPAND and then I decided not to use it.
 
perhaps you can do for(auto x : { ... }); :)
 
@Potatoswatter It can't be a function template because the order of evaluation of function call parameters is unspecified
Well it can be but that's not what you want.
 
2:17 AM
@LucDanton LOL… nobody expects the Spanish Initialization
 
but i'm not sure if that's any better than manually constructing the init list. perhaps the best is little macro. #define forall(...) initializer_list<int>{ ((__VA_ARGS__), void(), 0)... } :)
 
@JohannesSchaublitb I'm not confident enough of my skills with the preprocessor, but is using variadic macros a trick to work with commas?
I typically do unary macros and wrap the call in extra parentheses.
 
note that you canot do nop{ ... } if nop is a function :(
yeah it won't bail out then if the code contains a comma somewhere
 
Hopefully generalized pack expansion will come next.
 
pack expansion into a comma operator sequence would be nice :)
 
2:20 AM
LOL… can't you just create a #define for the comma-containing code, and pass that to the function-style macro? After all you apparently love the preprocessor…
 
@JohannesSchaublitb Into any operator sequence…
 
Seems somewhat more roundabout that just doing MACRO(( args )). I don't think I get what you mean :(
 
since the comma operator is at the very top, it would automatically work with anything
or do you mean 0 + t... would be 0 + t0 + t1 + t2 + ... ?
i think 0 + t... would be ambiguous. it could also be 0 + t0, 0 + t1, 0 + t2 ... then
 
@JohannesSchaublitb I'm thinking t + ...
Since for comma it would be t, ... right?
 
2:23 AM
yeah I think that's t0, t1, t2 ...
doesn't need a , at all
you don't need a comma in a f(t...) either
 
True.
 
or do you mean that OP ... would be a special expansion
 
Could go either way.
 
so that a / t /... (where t is the pack) would be a / t0 / t1 / t2 / ....
 
Or both.
 
2:25 AM
could be difficult to spec, because it's not clear what should happen with the fist / to me
perhaps one can say t /... and it expands to t0 / t1 / ...
 
Also, f(t...) works with empty tuples.
 
Since / is left-associative, the left operand of / would form part of the repeated expression.
1 / t / ... => (1 / t0) / (1 / t1) / (1 / t2)
 
then if we have a pack of member pointers we can do a . t .* ...
would that mean a. t0 .* t1 .* t2 .* ... ?
but one would need to spec what happens with an empty t -.-
 
Hmm, my interpretation sucks. There has to be an off-by-one adjustment to the associativity rules.
 
if (a, t...) becomes (a), (a .* t... ) could become (a) too.
 
2:30 AM
yeah, they fixed the spec in the FDIS so that struct A : T... { } works too
they will just remove the : if T is empty
 
[a] OP pack ... => [a] OP p0 OP p1 OP p2 ..., or [a]?
 
@LucDanton i see
 
Writing +t... looks like +a though.
 
I think t +... is less ambiguous
 
And is inconsistent with t...
but so is +t... heh
 
2:33 AM
t ,... would be equivalent with t ...
the rationale would be: , is the most toplevel operator
 
What does that mean?
 
@JohannesSchaublitb t ... could refer to the argument-list , and t, ... could specifically refer to operator ,
 
the natural semantics for t ... is to sequence it. i,e comma operator, i.e t ,...
 
so t... for what we have, but not for plain t...;
 
@Potatoswatter t... cannot refer to an argument list. there is no argument list att he toplevel
 
2:35 AM
@JohannesSchaublitb t ... only refers to an argument list, at present XvD
 
f(t...) is always an argument list I would say. f(t ,...) is always an argument list either, I would say
 
It's true that the commas play a different role as when they're an operator
 
but t ...; is the comma op always. t ,...; either, I would say
 
Is that what you meant by the toplevel thing?
I get it now
 
i mean, it has the least precedence.
 
2:37 AM
I'm not sure it's meaningful when , is not an operator but part of the syntax
Still, the special role of the comma in the syntax rather than as an operator is justification enough for me.
f(,,,,) is special.
 
The main reason for op ... is to disambiguate precedence. Otherwise 1 + 3 * t ... and 1 + ( 3 * t ) ... (might) mean different things.
 
i would spec both as 1 + 3 * t0, 1 + 3 * t1, ...
 
So I prefer 1 + 3 * t * ... for the former, and 1 + 3 * t + ... for the latter.
 
What happens if t is empty though.
(unrelated, sorry)
 
Parser has to be smart and delete the generic term.
 
2:39 AM
yeah in my proposal the former would mean 1 + 3 * t0 * t1 ... and the latter would mean 1 + 3 * (t0 + t1 + ...)
 
Not really that hard at the semantic level, I think…
 
I thought you wanted pack OP... too
 
@LucDanton yeah. i mean the meaning, not the syntax. I think I prefer the syntax that @Potatoswatter showed too
 
But what the operator for the second one?
 
@JohannesSchaublitb I think that goes against usual mathematical notation…
 
2:41 AM
Oh wait you refactored
Or, factored.
 
i think it means 1 + 3 * (t0 + t1 + ...)
lol
 
Sorry I was stuck in syntax and was thinking of 1 + 3 * t0 + 3 * t1 ...
Laziness being a virtue I decided not to go further from that
 
one could get that meaning with 1 + (3 * t) + ..., I think
 
Meh… this problem really is already solved by expression templates and the likes of std::accumulate
 
So what to make of 1 + t + ... when t is empty?
 
2:44 AM
@LucDanton Both the + operators are "deleted".
That's why I think it's better to think of everything between the equal-precedence operators as a single generic term.
 
So it's [a OP] pack OP ...
 
Right.
 
i.e the pattern would be detected by looking for the expression directly preceeding the OP, which in that case is a primary-expression (parenthesizsed expression).
hm wait, that is ill. it would fail with t / 2 *... because 2 is not a valid pattern -.-
 
That means that a pack + operator expansion can 'taint' adjacent expressions iff it's the same OP
 
additive-expression:
multiplicative-expression
additive-expression + multiplicative-expression
additive-expression - multiplicative-expression
multiplicative-expression + ...
multiplicative-expression - ...
 
2:47 AM
@JohannesSchaublitb It's acceptable to require parentheses here I think
 
I see. I agree
 
Are you comparing to e.g. f(t / 2...) ?
 
@LucDanton The same problem exists in any case, only the precedence of the tainted operator varies.
 
@LucDanton i think the f(t / 2...) case has the advantage that it always knows how much it takes as the pattern. it will just take the whole parameter
 
Yes, it never has to account for the /.
So ... what does 2 * t + ... become again?
I'd really like to require parentheses
Wait that doesn't solve everything
 
2:51 AM
@LucDanton Are you asking me? I'd have it be (2 * t0) + (2 * t1) + (2 * t2)… since 2 * t is the multiplicative-expression.
 
Making expressions vanish when the tuple is empty is still bizarre and not just for arithmetic in fact
 
yeah I think I agree to the idea: Everything to the left (for left associative operators X) or to the right (for right associative operators X) is taken to be the pattern, until the first operator Y whose precedence is less than the operator X
 
So "do the right thing" when it comes to expressions
 
this also means that a + t ,... has the same meaning as t + a ,... because any operator has higher precedence than ,
 
brb gotta put dinner on
 
2:53 AM
And in practical terms one has to be explicit for the empty case, as in T result = 0 + (t + ...);
Not sure if this works out
Heh bad example
(0 + (1 + t...)) / sizeof...(T) works, doesn't it?
 
one needs special rules that say that an () will be deleted, and a foo OP will become a foo etc.
 
Again, bad example
(0 + (sqrt(t) / 2...)) / sizeof...(T)
Pulling formulas out of thin air
 
So letting ... match according to precedence is very comfortable for subexpressions.
 
what would (0 + (sqrt(t) / 2...)) mean
 
2:57 AM
Care has to be taken for the final expression/statement but that is to be expected.
Out of curiosity is (sqrt(t) / 2...) / N well formed then t is empty?
Does the rule about foo OP extend to OP foo?
 
in my current thought model, (sqrt(t) / 2 ...) would mean (sqrt(t0) / 2, sqrt(t1) / 2 ...)
i.e op, because I took that as the "default operator" when no opeator preceeds the ... token
so that one can simply say cout << t ...; and it would just print out all t's. or one could say ++t...; and it would increment all t's etc
 
I thought we were going with the version that does magic according to precedence.
 
Let's not bring unary operators in there just yet!
 
haven't understood what (sqrt(t) / 2 ...) would mean yet :(
 
3:02 AM
If I ever had any doubt about why all of this wasn't specified in the FDIS, now I know!
 
Heh… I think I'd just stick to higher-order functions on expression templates :P
sorry for bringing the idea up guys lol
and of course my grammar above is broken… I never get grammar right on the 1st try XvD
 
If design by committee is this fun with just us 3, imagine the riot they have when designing the language.
 
Well they start off by separately writing dozens to hundreds of pages of papers…
Still no upvotes on my meta feature request :v(
 
1
Q: How to access unnamed "enum class" encapsulated inside a class ?

iammilindclass A { public: enum class { HELLO, WORLD }; }; Having known that, inside a class, declaring a simple enum (rather than enum class) is a better idea, because it's already typed with the class identification. But still above statement is a valid C++0x signature. Now how to access an unnamed ...

That one surprises me
 
3:13 AM
I'm too hungry right now to sort through the standard's rules, but I remember that the paper on this had a lot of insightful examples.
It's possible that G++ is just being too tolerant at the moment, and that's not really legal.
 
So it seems.
 
Hmm, I definitely recall a list of examples marked valid/not valid. I'm not seeing it in N2347…
 
I knew how it worked but I've never realized it before that struct A { struct { int i; }; }; and struct A { struct B { int i; }; }; are nothing alike.
 
in C1x you can say struct B { int i; }; struct A { struct B; };
 
What's the second thing?
 
3:20 AM
(iirc). and you can then access a.i as if the i would be a member of A
 
That's uh.
 
that is, inheritance in disguise
 
I was going to say completely not convenient
 
@LucDanton Unless something changed, struct doesn't work like union there. You'll get an error that the declaration declares nothing.
 
lol
But it's C1x. not C++ not C++0x
 
3:21 AM
But of course I immediately thought of struct A: B {}
 
… nope, I'm wrong. Too much C :v( .
 
Plus you have the room to add: struct totally_not_derived { no_vtable_here pointer; struct definitely_not_a_base; };!
 
Nope, adding --pedantic causes G++ and GCC to properly reject your example, @Luc. I was right, ideone was wrong :vP
 
yes his example is not valid
it would declare an anonymous struct
 
Is it C99 then?
 
3:25 AM
i don'T think that C99 has anonymous structs or anonymous unions
 
If this is an extension I'm going to feel hurt.
 
I did a bunch of embedded C recently and was really surprised by the lack of anonymous unions. They would really come in handy for that language, but nope.
 
btw it's main(void) right?
main.c:4:6: warning: declaration does not declare anything
main.c:1:8: warning: struct has no members
main.c: In function ‘main’:
main.c:11:6: error: ‘struct test’ has no member named ‘i’
This is the C99 pedantic error message as opposed to being rejected in C89 mode.
So C99 accepts it but it doesn't do anything
WELP so much for my education.
The weird thing is that I've always compiled in pedantic mode ever since discovering the option. So I've used anonymous structs/unions but not after I've discovered -pedantic and I've never heard/read anywhere that this was an extension.
 
@LucDanton Anonymous unions are OK, but only in C++.
 
I've never had a reason to use them with C++ so it's not that though.
Aaaand now I'm wondering if struct A { union U; }; will be valid C1X
 
3:34 AM
anyone here know how i set bounty on my own question?
 
@TrevorRudolph There's a minimum time before bounties are allowed.
 
oh
kool
do you know that time?
 
grumble grumble FAQ
> Questions must be at least 2 days old to be eligible for a bounty.
 
Foo
3:51 AM
hello
 
A foo walks into a bar…
 
Foo
haha
just a quick question, what is the most elegant way to build a string from variables?
is there a better way then using snprintf?
 
Knowing nothing more about the problem, ostringstream is the first line of defense.
std::string s = ( ostringstream() << 1 << " hello " << 2 ).str();
 
@Potatoswatter A lounge, not a bar. If it was a bar, maybe I could afford to drink!
 
Note that this one-liner style has some gotchas, so you're usually better off declaring a separate ostringstream object.
bar_and_grill< C++ >… now we're talkin
 
Foo
3:58 AM
:D
 

« first day (237 days earlier)      last day (4704 days later) »