« first day (167 days earlier)      last day (4784 days later) » 

12:52 AM
1
Q: Why is this program erroneously rejected by three C++ compilers?

James McNellisI am having some difficulty compiling a C++ program that I've written. This program is very simple and, to the best of my knowledge, conforms to all the rules set forth in the C++ Standard. I've read over the entirety of ISO/IEC 14882:2003 twice to be sure. The program is as follows: Here i...

I don't know what I'm doing wrong and the compiler error messages are totally unhelpful. :'(
 
 
3 hours later…
3:45 AM
A bit slow today.
 
 
4 hours later…
7:32 AM
I wonder if my pc is playing an aprils fool joke on me. Right mouse button stopped working
Then 15 minutes later, the left one stopped working
then I rebooted. Now I'll wonder all day what would've stopped working next if I hadn't done that
 
sbi
@jalf Next thing dying would have been the capability to reboot. :)
 
gotta love a function documented with the one comment: // Works!
at least it's not a question mark at the end
 
sbi
Ah, every day should start like this: deleting around 1500 lines of someone else's code :)
@jalf: Even better are those days where I'm deleting massive amounts of my own code. That is code I am responsible for, after all, if it blows up. If someone else's code blows it, I can always grin or yell at them.
 
@sbi the twist here is that the "someone else" in this case no longer works here, and I'm tasked with maintaining his code
and in that case, nothing beats deleting his code!
 
sbi
@jalf Someone else's code you are responsible for is the worst kind of code!
3
@jalf Indeed. Code that got deleted, can't fail anymore.
 
7:42 AM
I don't even count n of lines I added, but I count the deleted one's
always nice to delete LoC.... lol
 
sbi
Hans has claimed our approach to testing is "unusual", but refuses to tell me why. I hate it when people do that.
 
 
2 hours later…
9:21 AM
Oh C#, why don't you support generic programming?
 
I'd say "don't test Debug" is just plain stupid.
 
sbi
10:05 AM
@jalf I hear you!
/// <summary>
/// Copies content of collection <paramref name="source"/> to collection <paramref name="target"/>
/// </summary>
/// <typeparam name="T">Type of items in collection </typeparam>
/// <param name="source">Source collection</param>
/// <param name="target">Target collection</param>
public static void Copy<T>(ICollection<T> target, IEnumerable<T> source)
{
    foreach (T item in source)
        target.Add(item);
}
:)
 
@jalf Because GP isn't important.
what are all those generics about then anyway?
 
10:24 AM
Sweet. I got the Tumbleweed badge
@ChrisBecke well, I have two unrelated, but very similar classes. With C++ templates, I could've just defined one function to work on both. With C# generics, I'm just screwed.
Generic programming != generics
Or, to put it another way, there's nothing generic about generics
2
 
@jalf interesting.... hmmm
@jalf doesn't the word "generic" imply usually that it can be applied to all cases, but I guess in programming that would be impossible, well perhaps with templates in C++, but I'm no expert in that to know...
 
@Tony they allow you to treat different types as the lowest common denominator, which isn't really the same thing. GP is about writing code that works with multiple types, not about reducing multiple types to the same little crippled common blob
 
@jalf yea so it can apply to all types? so isn't generics then a misnomer?
or have I gone out of my mind... :p
 
Xeo
@Tony well, it somehow works, since everything in c# derives from Object afaik. Nothing like the true c++ template power though
 
@Tony not sure what you mean - but yes, I'd say generics (the language construct) is badly named.
 
10:39 AM
@Xeo true that, I forgot that all derives from Object.... wonder if that comes under the heading "OO Wanking"?
@jalf just meant that when you create a generic of T then T is supposed to be able to take any type, however in reality that isn't the case...
 
@Tony ah, yeah, agree then
Although it can take any type... As long as you promise only to treat it as if it had type Object
 
sbi
@Tony The problem with .NET generics is that you need to explain before-hand which operations the type is supposed to support, usually by pointing to the common base class. It's far less powerful than templates in C++: stackoverflow.com/questions/3071450/…
 
@jalf which makes it impossible to call a method from a specific type....
 
exactly
 
@jalf i think youre conflating meta programming with generic programming.
 
10:43 AM
@sbi Having to specify that before-hand is, in itself, not a crippling problem (it just makes it more tedious to write generic code, not impossible). The real problem is that you're so limited in how you can make this specification (as you say, primarily by pointing to a common interface or base class)
@ChrisBecke I think I'm not.
Say you have two classes, both with a Foo() function. GP lets me write a common function which calls Foo() on its argument type, without relying on metaprogramming
And generics don't let you do it.
Of course, in more complex cases, there's an overlap between GP and metaprogramming, and I'd love to have both, but C# gives me neither.
 
@sbi oh I hadn't actually thought of doing it with a common base class. This however then comes back to the fact you have to restrain T to only take types derived from Base, and nothing else.... which isn't then truly generic in its truest sense of the word
 
@Tony yeah, it's basically a promise that "you can treat all subtypes as their base type", which we could do without generics too
 
@jalf run time polymorphism is supposed to do that
 
@Tony exactly
 
so in that respect, c++ templates are much more flexible... :)
 
10:47 AM
@Tony or much more generic ;)
 
@jalf yes! :) w00t w00t
can you with C++ templates achieve true genericity even when you are calling a function f on a specific type through T, or do you then have to specialize?
 
@Tony um, you lost me
 
@jalf no worries.... maybe I was getting too philosophical or something
 
sbi
@jalf Yeah, that's right.
 
--> <-- --> pointers swinging
Loop unwinding, also known as loop unrolling, is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size (space-time tradeoff). The transformation can be undertaken manually by the programmer or by an optimizing compiler. The goal of loop unwinding is to increase a program's speed by reducing (or eliminating) instructions that control the loop, such as pointer arithmetic and "end of loop" tests on each iteration; reducing branch penalties; as well as "hiding latencies, in particular, the delay in reading data from memory". Lo...
 
11:11 AM
random link of the day?
 
@jalf yes, totally at random
 
11:38 AM
ah, I guess SO went into aprils fool mode
 
@jalf why'd you say that?
I haven't fooled anyone...
 
@Tony I said SO, not "Tony" ;)
try upvoting a question or an answer
 
@jalf lol hahaha :)
@jalf so what kind of things do you code?
 
@sbi yes but it doesn't count until I have noticed it ;)
@Tony at work? Right now, integration/synchronization between an Exchange server and another system
in C#, and because I'm pretty much the only one at the company who knows the language, I'm maintaining it ;)
when I have a choice (i.e. I'm not at work), I generally work on my C++ transactional memory library
btw, xkcd's april fool's joke is pretty impressive
converting the archives must have taken a fair bit of time
 
12:09 PM
@jalf I follow the RSS and would have missed it if someone didn't have mentionned. I still prefer the shell version :-)
But it is impressive.
 
@AProgrammer yeah, that one was great too
 
@jalf oh interesting
@jalf hahah yes
@jalf that sounds rather complicated material :)
 
12:42 PM
@Tony it is. ;)
it started out as my masters thesis at university. Then a few months ago I decided to polish it up a bit more
 
@jalf cool man :)
 
well, most of the complicated bits were more or less done as part of the thesis work. So now I'm mostly just making it faster, and easier to use
getting to the point where I actually suspect it could be useful in the real world with a bit more work ;)
 
12:56 PM
@jalf nice
so what degree did you do at uni?
 
@Tony computer science
 
@jalf oh cool, well if you've done that, I'm sure you have enough understanding of things to be able to write such intricate libraries
i'm a mere self-taught mortal :p
 
@Tony eh, it's not as complicated as it sounds, really
 
@jalf oh ok
 
If you know threading and maybe the very basics of transactional databases, there should be nothing too surprising in it
 
1:03 PM
not as complicated as 3D graphics programming.... lol
 
@Tony I know a lot of people who have a Computer Science degree from a prestigious university but who couldn't code a "Hello World" that didn't leak.
3
 
@JamesMcNellis that scares me!!!
@jalf threading I'm familiar with, but not so much transactional db's
 
@Tony well, if you know what guarantees a transaction offers, you're pretty much home free ;)
specifically, the ACID properties
 
@jalf oh ok cool :) however implementing transactions I can imagine isn't a simple task, it's said in a sentence, but definitely not written in one line of code
 
the basic idea is just to allow the user to specify blocks of code, within which any access to a shared variable behaves as if you were in a singlethreaded environment (that is, the Isolation property, basically), and then when the block exits, you make those changes globally visible atomically (the Atomicity property)
which is done by taking private copies of the necessary shared variables, and then assign them back into the global ones when you leave the block
 
1:10 PM
oh I see, well that makes sense, thanks for clarifying :)
 
so the basic idea is simple enough. The tricky part is doing it efficiently, while still avoiding race conditions
 
@jalf yea I can imagine that is tricky
so is that the kinda thing that interests you?
 
A lot of things interest me ;)
I ran into this subject completely by accident when I was about to start on my thesis
and it seemed interesting, so hey, why not work on that
 
@jalf cool man! :)
 
I decided to study CS because I wanted to make games, just like millions of others
 
1:13 PM
@jalf not a bad choice
I'm trying with graphics right now, I get a bit lost in the math side of things
 
still wouldn't mind doing that, but in the meantime I found about a million other things that it'd be interesting to program :)
 
but I'm digging through
 
:)
 
CUDA is interesting too
 
yeah, definitely
one of the funny things about my STM project is that all the other implementations are so obviously bad from a plain code quality pov. It's all terrible C-style code with macros everywhere, and which either requires you to share only built-in types like int, or require you to derive shared objects from some common base class
 
1:17 PM
@jalf yep a lot of bad code out there
 
so one of my goals was just to create something that felt like modern C++
 
@jalf yes I like modern C++ :)
 
:)
 
I'm thinking that financial programming must be quite interesting too
problem is I cannot quite make up my mind which area I want to specialize in
I'm not sure if that's a bad or good thing.... I have interests in quite a few areas, but obviously it's hard to keep doing them all
 
yeah, I know the feeling :)
 
1:21 PM
its funny how the really enthousiastic dev's hang out here and the one's that do it for just their "job" don't come here very often
some coworkers of mine are devs, but they do not spend any time talking with other like minded people, as they are just doing a "job"
 
what do you work with?
 
@jalf C++ right now
good day @FredOverflow
 
well, doing what in C++, I meant :)
 
@jalf server application that handles database requests from multiple clients, does calculations and executes Python, VBscripts and SQL
fun :)
 
@Tony yeah, sounds good :)
whatever happened with the mem leak you were hunting btw? Did you decide it was a false positive?
 
1:31 PM
Are there any biographies of famous computer science people?
 
@jalf yea, it was a false positive, cause I ran it through another mem leak detector and it turned out nothing, and @David ran it through a Linux mem detector that also turned up nothing, so I guess there was no leak to begin with
 
@FredOverflow Charles Babbage wrote an autobiography
 
Did Ada Lovelace help him? ;)
 
I assume it was after she died
;)
 
Why, does it contain a chapter about her? :)
 
1:34 PM
@FredOverflow no, but she died pretty young. Babbage didn't.
 
@jalf The twitter/fan part is awesome :)
 
hehe
ok, I'm heading home. Talk to you later!
 
2:10 PM
@FredOverflow there was recently an article about Babbage in the IEEE Annals of the History of Computing
his early years
 
2:22 PM
wow, got quiet after I left ;)
 
yep
 
Xeo
Holy...
i just saw some unicorns dancing..
 
@Xeo should I be worried now?
lol
 
@Xeo so did I
after only 1 day of sleep deprivation
that's a first
 
Xeo
and I even slept this night
 
2:29 PM
something is in the atmosphere
 
Xeo
OH MY GOD THAT UNICORN JUST DID A THUMBS-UP ON ME
holy cow, I think I need to get my water checked
lol, the downvote ones..
 
2:51 PM
does anyone here use c++ for embedded applications - microcontrollers, bare metal or RTOS?
 
@rmaVT , I write software that runs on an RTOS. I'm no expert though (recently started this job)
 
@StackedCrooked, so are you using c++ or c, or both?
 
I've seen a good handful of answers on SO by people who use C++ in embedded software. It can certainly be done, if that's what you're wondering. :)
 
@Xeo I didn't know unicorns had thumbs
@rmaVT yup, that's what I do
all day, every day
 
Xeo
@RonaldLandheerCieslak I didn't know either until then
 
3:06 PM
@rmaVT C++ although much of the code is written in C-style
 
I know it can be done. I seems like kind of a niche though. By that I mean it seems difficult to find the core community for that. Lots of discussion about c++ with large memory spaces, using boost and the STL, not as much about using c++ with limited resources
also, there are so many different tool chains, it can be difficult to glean a set of best practices from what other people are doing out there. I use Keil MDK-ARM/uVision 4
 
@rmaVT I believe the Poco C++ library also targets mobile devices (and I know it being used in iPhone apps).
 
@RonaldLandheerCieslak What tool set do you use? What kind of target?
 
@rmaVT currently: MS Platform Builder on an ARM
but I've used others
currently, I'm in an MS world..
 
I'm trying to put together some process improvements like unit testing, a build server (continuous integration). There are definitely special problems applying that to embedded, but I think it's worth the effort.
 
3:21 PM
@rmaVT definitely worth the effort, embedded or no
 
@rmaVT, I could be wrong, but I have the impression that the choice for C instead of C++ for embedded programming is based on some sort of superstition.
 
@RonaldLandheerCieslak Most of the "professional" embedded tools seem to stick to the MS world. Android has brought more out, but Keil, IAR, GreenHills, and TI are all deeply tied to Windows
 
@StackedCrooked sometimes you don't have exceptions, sometimes you don't have the STL, but you still have better type safety and all the other goodies C++ has over C
@rmaVT I've been working with Green Hills' Integrity too - but that was just C (due to the same superstitions @Stacked talked about)
 
@RonaldLandheerCieslak So what have you got setup as far as development team tools go?
 
@FredOverflow where did you learn about INITCOMMONCONTROLSEX? Was it due to my post on reddit yesterday? :)
 
3:26 PM
the usual MS stack as far as my current job is concerned
before, I used more open source tools (git for source control, bugzilla for bugs, etc.)
but my current job is at an MS outlet of sorts
I don't mind, though - some of the MS tools are pretty good, and the others I can live with
i miss git, though.. :'(
for my own projects, I use the GNU toolchain, git for version control
 
git is awesome. MS tools are really good for .NET and other MS stack related projects. In my experience so far, Keil is pretty bad. It appears that they assume you won't be working with any other developers - lots of user specific stuff get's mixed up in project files, and their tools are difficult to drive from the command line. That's been my experience anyway.
 
I gotta go - cu l8er
 
@RonaldLandheerCieslak hey thanks.
 
4:00 PM
I got my head around union's and how you can use them, but I can't see what they offer exactly that you couldn't do with out them. surely you can just type cast to get the same effect as a union. Is it just that unions are more explicit in how you are dealing with the data?
 
Xeo
@thecoshman unions are useful in a number of ways. eg when you know you can have different types, but know for sure you'll only ever access one at the same time. if you know the JSON format, most C++ implementations are done with a union. also, the Boost.Variant imitates the union behaviour with placement new and a storage buffer equal to its largest type
 
They automatically take as much space as biggest element. If you just cast things around, you will have to keep track of it manually. I never had to use them in C++ outside of API calls though.
 
Unions are type-safe, blind casting is not.
 
Xeo
4:18 PM
@PiotrLegnica unions allow a horrible_cast from any type to any other unrelated type. :)
4
 
Well, a bit more type-safe. At least you know which type could've been used. :P
 
hmm... mostly what I thought...
more a nice thing to be able to use some times but not something you are going to be using all the time
 
4:42 PM
@Xeo technically you are only allowed to read the union value that you last wrote to (otherwise it's UB)
 
A typical use of a union is dealing with network packets. For example, you have an IP packet. Inside of that you have some sort of higher-layer packet: TCP, UDP, SCTP, RGMP, IGMP, etc. Picking just one of those, inside a UDP packet you have another layer: RTP, RTSP, SIP, SCCP, etc. It's certainly possible to (for example) have a pointer to each possible type, and cast appropriately. Its often useful, however, to treat the packet itself as the union of protocols it could be.
 
@JerryCoffin interesting, this is very relevant for my current job.
 
why does it say binary '[' : 'DoisD_' does not define this operator or a conversion to a type acceptable to the predefined operator:

DoisD_::DoisD_(int lin, int col):maxLin(lin), maxCol(col){a[] = new double[lin];}

int main(){
...
DoisD_ dd(lin, col);
for(i= 0; i < lin; i++)
	dd[i] = new double[col];//happens on this line
}
 
1. Initialise all variables in the initialiser list. 2. Did you overload operator[] for your type? 3. Use std::vector.
Or here probably boost::multi_array would be better.
 
@PiotrLegnica no, didnt overloaded
 
4:52 PM
Then that's why it says you didn't do it.
 
Xeo
@StackedCrooked right, i always forget about that..
 
@Xeo heh, I only learned this a few months ago.
When implementing the subscript operator, what are the restriction for the index type?
I thought it had to be a type that implements operator<. But I think I'm wrong...
 
Why would it have to have <?
 
@PiotrLegnica in order the values to be comparable.
 
Xeo
@StackedCrooked you can implement the subscript operator for any type you want
it solemnly depends on how you use them in your operator
 
5:04 PM
Hm...
 
Index type might have ordering, but that wouldn't make much difference in e.g. hashmap.
 
Xeo: A quick experiment proves you right. Strange, in the past I always seemed to stumble upon a compiler error when using a non integral type..
 
btw, either I'm completely losing my marbles, or gcc 4.6 is buggy as hell
 
New GCC versions are usually buggy.
 
these are surprisingly obvious though. I instantiate a function template with two template types, T1 and T2, and in the compile errors it then claims that the type of T2 is whatever T1 was supposed to be. And it doesn't seem to like anonymous namespaces
 
5:14 PM
@jalf then it probably doesn't it work with stl and boost?
 
does it work with gcc4.5 ?
 
user379888
Can anyone help me with the concept of inheritance and aggregation . I have made a class shape and other classes are derived out of it which are freehand, rectangle, circle, rubber. Can the placement of freehand and rubber be justified in shapes with the help of aggregation?
 
Is this legal code (incrementing the values without initializing them to zero first)?
std::map<std::string, int> wordcount;
wordcount["radio"]++;
wordcount["tv"]++;
 
map::operator[] default-constructs the value, so it should be. But then again, even if it works, it's confusing IMHO.
 
Xeo
piotr is right, i think they are even value initialized
 
5:27 PM
It is inialized as "mapped_type()" in the Visual Studio implementation. So that's fine. I'm just wondering if this is also required by the spec.
 
default initialization in c++0x for "int" will leave the int with indeterminate value
 
@JohannesSchaublitb is this different from the current C++?
 
for sure. in current c++, default initialization for "int" will give value 0
 
So it's a breaking change?
Runtime-breaking, not compile-time-breaking, I mean ;)
 
it's not a breaking change. it's just a terminology change
people that meant the term "value initialization" for "int()" but incorrectly referred to it as "default initialization" when using C++03 will be forced to change their terminology because now the mistake is obvious
 
5:33 PM
Ah I see. So default initialization simply refers to "int a;", which always gave an indeterminate value
 
@StackedCrooked That's not initialized, not default initialized (c++03 speak).
Both default and value initialization perform zero initialization for int.
 
yes. in C++03, "int a;" didn't receive default initialization, but rather no initialization. in C++0x, it receives default initilaization. And default initialization is changed for non-class types to do no initialization
 
@CharlesBailey so "default initialization" was a non-existing term?
 
Xeo
@StackedCrooked it existed, but only for class types
 
default initialization in c++03 only made a difference to value initialization for class types afaics
 
5:36 PM
@StackedCrooked No, it existed, and it (default-initialization) occured in several circumstances....
 
Xeo
@CharlesBailey i think there was a question somewhere on SO asking for an explanation on all those different initialization types
 
@Johannes, so in my code sample above, the value (of type int) is not intialized?
 
@Xeo There are several.
 
default initialization occurs for non-POD class types when an explicit initilaizer is missing for a declaration A a; or when a default constructor is executed and the member is not mentioned in the constructor initializer list and is of non-POD class type.
@StackedCrooked yes a is not initilaized in C++03, but in C++0x default initialization is performed. But it in the end also doesn't store any value in a.
 
5:38 PM
default-initializing for int and other POD types occurs relatively infrequently in C++03.
 
best you just read the spec then you know it all
 
Xeo
but it seems that needs to be edited for c++0x?
 
@JohannesSchaublitb, I'll stop bothering you soon :), but what about this code sample:
std::map<std::string, int> wordcount;
wordcount["radio"]++;
wordcount["tv"]++;
Will the mapped values be undetermined? Or equal to 1?
 
@StackedCrooked Value initialized. operator[] is defined as being equivalent to (*((insert(make_pair(x, T()))).first)).second
T() is a value-initialized temporary which is copied into the map and then incremented by the post-fix ++.
 
@Charles, thanks. And value-initialized means initialized to zero?
 
5:47 PM
@StackedCrooked For int, yes.
 
Ah cool.
 
Xeo
@CharlesBailey could you make that more complicated? ;)
 
@CharlesBailey yet, I think many would frown if above sample appeared during a code review
In production code it's usually the convention to be very explicit and allow no room for ambiguity.
 
If you were implementing map, you just have to write something that's equivalent to that. You wouldn't have to put it all on one line.
 
sbi
@StackedCrooked I doubt that. Counting words is the standard example for using a map that inserts values when you access a non-existing key. You'll find this one in just about every textbook explaining std::map.
 
5:57 PM
@sbi I don't remember this example from by textbooks :)
@sbi What exactly are you referring to when you say "I doubt that"?
 
sbi
@StackedCrooked Then you read the wrong ones! :)
 
I learned C++ from Accelerated C++ about 5 years ago.
I've forgotten much of the examples.
I'll check, sec.
 
sbi
@StackedCrooked When you hover over a message that refers to another one, the other one is highlighted. If that's not enough, click on the referring pointer on the left.
@StackedCrooked That's a good book. It taught me how to teach C++. :)
 
Xeo
i think i need to get (more) effective c++ sometime..
 
Yeah I think it was a good start.
 

« first day (167 days earlier)      last day (4784 days later) »