« first day (112 days earlier)      last day (4818 days later) » 
00:00 - 21:0021:00 - 00:00

12:03 AM
[](char c) {
    char c=std::lower(c);
    return c < 'a' || c > 'z';
}

compiles on g++ 4.5.1. Don't I have to I specify the lambda's return type?
Argh. I mean std::tolower().
 
no
you don't have to specify if it's only got one return statement, I believe
 
12:39 AM
@wilhelmtell don't know about the fancy newfangled lambda thing, but you should do char c = char( std::tolower( (unsigned char)c ) );, otherwise you're mostly in UB-land
 
user418827
Good morning.
 
only norwegians here
 
user418827
Hei!
 
user418827
I believe you are the first norwegian C++ coder I've talked to, except for myself - a rarity indeed
 
12:57 AM
@Øystein oh. you can check out Oslo C++ Users Group.
 
user418827
@Alf: Thanks for the tip
 
@Øystein you're welcome. another way to meet up with norwegian programmers, at Norsk Freakforum ;-)
although mostly students there
 
user418827
@AlfPSteinbach Huh, that site really has a section for everything..
 
user418827
Haha even pyrotechnics! I'm impressed.
 
1:12 AM
1
A: c++ varargs/variadic function with two types of arguments

Alf P. Steinbachsince you're doing c++ there's no need to use untyped C-style variadic function. you can simply define a chainable method like class Inserter { public: Inserter& operator()( char const* s ) { cout << s << endl; } Inserter& operator()(...

could someone please help vote to approve Xeo's edit of my answer
i voted to approve but it says it needs more votes
i don't understand, since it's my answer, but, more votes needed!
 
user418827
I would, but I don't have enough rep.
 
Tip: you can gain rep by synchronizing you SO account with accounts on sister sites
Or possibly that's only rep on sister sites
not sure exactly but worth investigating. i did that to gain enough rep to join chat when OpenId went down so I had to create new account to log on
like, "fastrep" ;-)
 
user418827
I already figured out that one, so now I'm stuck with nothing but hard work :)
 
user418827
I think I only got 100 rep, though.
 
yes, thereabouts
per site
i think
 
user418827
1:19 AM
It's an easy start, though - motivating for new users (or me at least)
 
1:36 AM
"The justice minister said local chiefs would deal with those caught breaking wind in public"
Reminds me of the scientist who was afraid he would never hear the end of it if he let wind in the echo chamber
 
@AlfPSteinbach sad conclusion: we can't be very optimistic about other people's cognitive capacity.
 
I notice I wrote "sister sites" above. Why are sites female?
 
user418827
1:56 AM
@Alf: Because there are guys all over them.
 
sbi
@AlfPSteinbach You wish!
@Tony great! It's now number for on those comments.
 
user379888
2:13 AM
@Xaade:Sorry couldn't reply you yesterday,was sleeping.
According to you,"You're not redeclaring it..... you're defining it.

It has to be initialized. Since a static variable can be used without a class, you can't very well initialize it only in a constructor.

So you must initialize it at global scope."

But if I am defining it,then consider a case where I need to calculate the number of objects created.I am incrementing count in the constructor to have a check for the objects created.I know that the static variable will initialize to 0 automaticallySo I do not need to define it at any ot
 
user379888
2:26 AM
Why isn't the unsigned data type not largely used?I mean when you know that a value is never going to be negative still many people use unsigned int's for that
 
user418827
It's really only useful if the number gets so large that it doesn't fit into a signed data type.
 
2:54 AM
@AlfPSteinbach std::tolower() takes a char, and std::string (on elements of which I call the lambda) is typedef'd on char. So why would there be a problem calling std::tolower() on a char?
 
3:39 AM
Hmmmmmm
 
 
2 hours later…
5:47 AM
@wilhelmtell no, the one-argument std::tolower takes an int
@wilhelmtell when CHAR_MIN < 0, sign extension will bite you in the ass
 
user379888
Can the members of a const object be modified?
 
@wilhelmtell "In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined." C99 §7.4p1
@fahad sometimes
 
user379888
@FredNurk:How and when?
 
when they are mutable or references to non-const, or pointers to non-const if you want to count the pointed-to object
and then there's always const_cast for when you have a constant reference to a non-const object
 
user379888
You can not call a non-const function in a constant object I think
 
5:52 AM
that's true, but I don't see how it changes anything said so far
 
user379888
What do you mean by reference to non-const?
 
@FredNurk What the hell? Codepad allows you to use cout without including iostream? I thought it was a real stickler for the rules.
 
 
2 hours later…
user379888
7:39 AM
Please help me out with this code ideone.com/Y86xu
 
8:42 AM
Sup all :)
Its not SO, but its C++, and I just want to very that its not my code causing the problem (without reposting the question on SO): http://askubuntu.com/questions/24901/sdl-fullscreen-and-gnome-panel

I'm freeing the surface and calling SDL_Quit... AFAIK shouldn't be my problem.
 
 
2 hours later…
10:17 AM
@wilhelmtell no, it takes int
 
10:53 AM
@wilhelmtell The compiler should not accept that code, in the C++0x final draft, 5.1.2/5 it says that if you omit the return type, and the lambda is a single return statement, the type of the statement is inferred, if the expression is not a single return (which it your case it isn't) the return type is void. On the other hand, I see no particular reason (besides standard compliance) why the compiler could not infer the type there, as that is exactly the same as:
[]( char c ) { return c=std::tolower(c), c < 'a' || c > 'z'; }
@PigBen That is why I prefer ideone.com (for the two times I have had to write a test online)
You have mistyped { (curly brace} as ( (parenthesis) as the opening brace of your constructor. Also, you have another error, with your counter. A static member attribute declared as:

class test {
static int value;
};

is defined as:

int test::value = 0;
Note: no static and the classname:: prefix. If you define static int value = 0; you are defining a namespace static variable (a variable that is at namespace scope that is only visible in the current translation unit)
 
 
4 hours later…
3:16 PM
ohai
 
 
4 hours later…
7:29 PM
Ew, resource management in Java :-)
0
Q: Closing nested Reader

FredOverflowWhen reading from a text file, one typically creates a FileReader and then nests that in a BufferedReader. Which of the two readers should I close when I'm done reading? Does it matter? FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(fileName); br = new Buffered...

 
I feel your pain
 
BTW, what a mundane question to ask as question #100 :-)
 
meh, who cares?
a question is a question is a question
 
I find question #99 a lot sexier, for example.
 
nah
I wish that I could erase the memory of that question from my mind
 
7:37 PM
:-)
I just made the Java question a little more interesting. Can you spot the difference?
 
it's Java
why would I want to?
 
To broaden the horizon?
 
uh, no
that does not broaden my horizon
it would involve reading a language that I already have tried and disgusts me
 
Well, Java is simple by design, which means it's not very interesting to study it for its language features.
 
I wouldn't call it simple
 
7:45 PM
BTW I just saw the 2nd Edition of the Scala book is out. I think I'm gonna buy it. Scala is a lot more interesting when it comes to language features :-)
 
more like, flat out wrong
 
Is there anything right with Java in your opinion?
For example, I think it does modules a lot better than C++.
 
hmm
 
And sometimes, Garbage Collection can be nice. But that's about it from my perspective.
 
that wasn't my experience when I actually tried it
some package bullshit or other
at least my C++ code doesn't change depending on it's file or folder location
 
7:47 PM
Oh and I like its simple interfaces.
@DeadMG Well that's all handled automatically by Eclipse, so I don't care.
 
it would also be simple to conclude that everything is edible
but as you would rapidly die of various horrific ailments, I think it's likely not the wise choice
 
@DeadMG At least now we know where your stomach problems come from ;-)
 
think I already asked a doctor
 
I don't like the way Java handles equality. You can compare all objects with one another, even if it does not make sense from a type perspective. And the implementation of equals just look horrible. Downcasting in an "OMG object purity!" language? Come on!
And Java's genericity has far two much quirks for my taste (thanks to type erasure).
That whole boxing/unboxing business is also stupid.
> I really want a vector of integers. I don't want a vector of references to objects containing integers. Not even if they hide that fact from me so I don't see it!
Who said that? :)
 
@FredOverflow GC is great with immutable types
but once you add mutability to "everyone owns everything" (which is GC), it's an equivalent mess to tracking object lifetime in a non-gc language
 
8:00 PM
much worse, imo
 
I think it's really equivalent
tracking "can I modify this" being the same as "do I own this"
 
@FredOverflow Good language should be designed with generics first. Possibly one does need runtime polymorphism also.
 
nah
because in C++, you can have non-tracked raw pointers
if I have a std::unique_ptr, I can dish out that ptr everywhere and still own it and not have any of the raw pointers to that object tracked
 
yes, c++ has the big boon of tracking ownership in the type system, which most other popular languages don't
 
mutability != ownership
 
8:04 PM
I didn't say it is
 
C++ does not track ownership in it's type system
 
but tracking mutability and tracking ownership do appear to be equivalent (but still not identical)
 
int* p1 = new int();
int* p2 = new int();
std::unique_ptr<int>( some_bool ? p1 : p2 );
 
@DeadMG didn't you just mention unique_ptr?
 
indeed
and I just demonstrated that it's ownership is not enforced by type system
 
8:05 PM
there you go, unique_ptr is a tool to track ownership in the type system
 
no
because you don't know the object that it owns
you don't know if a given unique_ptr owns any object
 
oh please, "it's not enforced that I must use a hammer with a nail"
but a hammer is still a tool to use with nails
 
you said that it was in the type system
but it isn't
 
std::unique_ptr is a type
 
and it can't enforce it's ownership
nor is the ownership tracked by compiler
 
8:07 PM
I'll just leave it here, you're not making any sense to me
 
it is up to me, the programmer, to make sure that my owning pointers own sensible things, at run-time
constness is enforced by the compiler
if I make a stupid with owning pointers, I will get no compiler error
 
@FredNurk Agreed, immutable types + garbage collection = big win.
@DeadMG But think about how long C++ had to evolve in order to support unique_ptr<T> :-)
 
that's not the point
we had owning pointers before unique_ptr<T>
 
Latest news: Malawi justice minister admits he was wrong about farting being a criminal offense
 
What Fred probably means is that when you see a function with a unique_ptr as its return type, you know statically that ownership is transferred to you. Of course you can do silly things like like handing out a unique_ptr to an already released object, but that's a weak objection. You can deliberately break anything in C++ if you want to. Remember, the programmer is always right!
 
8:12 PM
no no
you know statically that ownership is supposed to be transferred to you
but it might not be
compared to const, where you have to explicitly request to cast it away
look, ownership is variable at runtime, even in your example you're transferring ownership - at runtime
if the compiler genuinely checked ownership, parallel code would be a hell of a lot easier than it is
 
@DeadMG The standard says "A unique pointer is an object that owns another object and manages that other object through a pointer", and it also mentions "transfer of ownership " explicitly. That's what we mean.
 
unique_ptr is a type that manages ownership
but the ownership itself is not part of the type system, it occurs at runtime
 
@DeadMG Okay. Just to get a better idea of what you're talking about, is there a language where ownership is part of the type system?
 
no
what would be the point of creating things dynamically if they can only be owned statically?
you could argue that stack-based variables are owned statically
as their ownership is fixed and cannot change
and is always known to the compiler, and indeed you can get compiler errors/warnings for returning references/pointers to them
 
@DeadMG I'm not sure I understand that argument. For example in Haskell, side effects are part of the type system, even though side effects happen at runtime.
 
8:19 PM
never used Haskell
beyond vomiting at the syntax
 
user379888
Does the default constructor initializes the values to 0 or garbage?or is it compiler dependent
 
default constructor for what?
 
@fahad Depends on a lot of things. Show us source code.
 
no default construction behaviour is compiler-dependent
 
user379888
My teacher told me that it is compiler dependent
 
user379888
8:21 PM
But I just saw in a video that the prof says it initializes with 0
 
It depends on whether you define a static variable or an automatic variable. Or whether you create a dynamic scalar with new or new() etc.
 
@FredO: No, fahad asked if it did
@fahad: No construction behaviour is compiler dependent, except in some debug modes the compiler will do additional behaviour
If you construct a scalar type without explicitly constructing it int a; versus int a(); then it will contain garbage
if you construct a UDT type then it will always have the default constructor called
 
@fahad "It initializes with 0" please be more precise. Are you talking about a class constructor initializing the members?
@DeadMG int a(); is a function declaration ;)
 
oh yeah
fuck you, C++
I'm so glad that I only program in my tiny little corner
 
user379888
8:24 PM
@FredOverflow: I am talking about the default constructor.What values does the default constructor provide the variables?
 
@AlfPSteinbach What is it? I can't watch in in Germany.
 
@fahad: It will default construct them
whatever that default constructor is
 
@FredOverflow 3 Doors Down "Away from the sun". Interesting video for anyone who's struggled with suit folks... ;-) It's based on idea of Sisyfos
 
@fahad I believe the default constructor does value-initialization. What that means depends on the context of creation.
@fahad Let me give you an example:
class Foo
{
    int i;
    std::string s;
}
 
@FredO: For non-primitive types anyway
 
user379888
8:26 PM
@DeadMG @FredOverflow: If it is an int,do you agree that it would always initialize wtth 0?
 
no
 
If you define a local variable Foo x; then x.i is not initialized, and x.s is default-initalized to the empty string.
If you define a global variable Foo x; then both x.i and x.s will be default-initialized (to 0 and the empty string).
 
it is perfectly legal for the compiler to leave uninitialized scalar types that are not explicitly initialized
 
user379888
So they propabally get garbage values?
 
user379888
Why does the string gets default initialized and int does not?
 
8:28 PM
because string is a UDT
int isn't
 
@fahad Because std::string is a user-defined type with a parameterless constructor that does useful stuff.
There is no such thing as an uninitialized std::string variable (oversimplified).
10
Q: What do the following phrases mean in C++: zero-, default- and value-initialization?

BillWhat do the following phrases mean in C++: zero-initialization, default-initialization, and value-initialization? What should a C++ developer know about them?

 
user379888
Why are user defined types initialized ?
 
user379888
:(
 
because they may have important initialization logic
whereas no primitive type has important initialization logic
 
@fahad Because the class concept would be useless without that guarantee.
A more sensible question would be:
> Why are primitive types not always initialized?
The answer is:
 
8:33 PM
because whoever wrote that part of the Standard was on drugs
 
> To be efficiency-compatible with C.
 
user379888
I am lost in the concepts of what is user defined data type and what is not
 
If my_struct_type x; had been potentially more efficient in C than in C++, nobody would have adopted C++ in the early days, and the language would have been stillborn. Simple as that.
2
@fahad class, struct and enum -> user defined types.
 
@fahad: If you define it, it's a user-defined type
 
user379888
till some moments ago,I thought that all those types which we define are user defined data types but I never knew that string is also included in the list
 
8:35 PM
if it came with the language, it's a primitive type
of course it is
it's a user-defined type
 
@fahad std::string is defined in the <string> header. You can look up the source code.
 
user379888
std::string comes with compiler
 
that user happens to be your compiler writer who is mandated to define it
but from a language point of view, it's a user-defined type
 
user379888
So everything else except iostream is user-defined?
 
@fahad a built-in type is like int etc., the concrete types you had in C + C++ bool and wchar_t. the standard uses unclear terminology about this. unfortunately.
 
8:36 PM
@fahad The "user" was the library implementor in that case. But there is still a class for std::string (well, a class template to be more precise...) whereas there is none for int. You cannot look at the source code for int :-)
 
iostream is user-defined too
 
@fahad iostream is also user-defined :-)
 
user379888
: p
 
any complex type is user-defined
the only primitive types are the very primitives, like int, float, char, pointer
 
@DeadMG Except complex in C99 ;-)
 
user379888
8:36 PM
So something I can do without a header file will not be userdefined : p
 
this isn't C so I don't care
@fahad: Any types you define yourself will of course be user defined
 
user379888
I did not defined string header file :p
 
@fahad Most probably correct.
 
@fahad headers and implementation files have nothing to do with it. the compiler proper does not know about header files. to the compiler proper it's all just text. hope that helps.
 
user379888
Still I get the idea that someone did that for me
 
8:38 PM
@fahad: you need a c++ textbook.
 
@fahad Yes, and that guy was a user who defined the type.
 
user379888
@AlfPSteinbach I have tons of them
 
@fahad i meant, you need to read one.
 
@fahad What have you got?
337
Q: The Definitive C++ Book Guide and List

grepsedawkProvide QUALITY books and an approximate skill level. Add a short blurb/description about each book that you have personally read/benefited from. Feel free to debate quality, headings, etc. Books that meet the criteria will be added to the list. Books that have reviews by the Association of C an...

 
user379888
I agree that these books might be amazing but I don't get much from them :(
 
8:40 PM
@FredOverflow exactly
 
user379888
I understand from youtube tutorials..they are helpful
 
@fahad Beware, at least 98% of the online material on C++ is complete bullcrap.
4
@FredNurk Great minds think alike :)
 
user379888
@FredOverflow: I agree to it,but even they do the same work what the point in sticking so much to the standard?
 
@fahad I don't understand what you're asking. Please clarify.
 
@fahad programming, in any language, is hard. not incidentally, it's probably as hard as learning a foreign (natural) language
 
8:47 PM
@FredNurk But you can't screw up that often in natural languages as you can in C++.
 
just like someone living in France for 15 years (without French as their mother tongue) would likely be exasperated explaining French to me, it takes a lot of work to explain C++
@FredOverflow they are more forgiving, since people are more forgiving than compilers and CPUs :)
 
@FredNurk Interest in history also helps. Most quirks in C++ just grew out of history.
 
unfortunately
 
Languages with a lot of history have quirks. It's something we have to live with.
Unless you want to hit the reset button every 10 years and invent a new, "cleaner" language this time :)
 
I learn a new language much more often than every 10 years ;)
I think all programmers who care about their craft have several ideas for what they'd do in creating a new ideal language
 
8:51 PM
Of course.
First it's the perfect string type we're after, then the perfect smart pointer, and then the perfect language :)
Ideally, I would want a simple language without lots of special rules, where the language features can be combined orthogonally in a nice way.
 
I would prefer a language that's encapsulated
 
In C++, you constantly have to say "Yeah, you can do that under normal circumstances, but not in a constructor" and stuff like that.
 
was reading about a language that took that approach, defining a very small core of which other features were defined
 
@FredNurk lisp? ;)
 
like, in C++, if you want to call a member function or a free function, you have to have different syntax, which I think is wrong
and you can't provide overloads for all primitive operations like dynamic_cast or sizeof
 
8:55 PM
even function returns were encapsulated as exception handling, which is this language's "core" control flow construct, with continuations, etc.
@FredOverflow it's a good example, but not what I was reading about
 
@DeadMG Operators being the exception to this rule :) Both member and non-member operators can be called with x + y. See, why this exception?
@DeadMG I think it would be quite dangerous to be able to overload sizeof. Also, how could that possibly work? sizeof is a compile-time operator.
 
I think that itwould be perfect
because you could natively create variable-length classes in an encapsulated fashion
the primitive sizeof is a compile-time operator
 
@DeadMG Variable length classes... wouldn't they have to be instantiated on the heap, always?
 
but in DeadMG++, it can be called at runtime, and receives the constructor arguments too
_alloca() is your friend
 
@DeadMG Not standard C++ I'm afraid?
 
8:57 PM
more importantly, when you overload sizeof(), then it means that my class has a variable size, independently of where it's allocated
@FredO: This is DeadMG++, remember?
 
@FredOverflow alloca is C99, iirc, and generally advised to be avoided
 
if you had a compiler extension for variable length arrays a'la C99, it would be trivial to handcode such a thing
allowing run-time sizeof() just makes it simpler and better encapsulated
 
@DeadMG If you have a class with an int* member and it owns an int on the heap, how much would sizeof yield? Just sizeof(int*) + sizeof(int) I guess? What about the heap management overhead?
Why would anyone care how much bytes an object needs in total?
 
if you have a class with an int* member, then sizeof(class) yields sizeof(int*)
firstly
because if you can make sizeof() runtime, then you can have it call across DLL boundaries and suchlike
 
00:00 - 21:0021:00 - 00:00

« first day (112 days earlier)      last day (4818 days later) »