« first day (12 days earlier)      last day (4919 days later) » 

12:00 AM
hah, got to say 0 seconds
 
@RogerPate I wish that was the way we get taught, we are trying to use a potential very powerful IDE with out really knowing what its doing. Our lessons on debugging where terrible, just press f10 till it crashes, then you know where to fix... yer... ¬_¬
 
@thecoshman If you're just going to go until it crashes anyway, you might as well hit F5 and let 'er rip. When it crashes, use the call stack to walk back through was was going on. Then again, that's not necessarily a bad way to do things either. It's often what I do first to at least see what general area of the code is leading to problems (and more often than not, careful scrutiny of a few preceding lines shows the problem).
 
@JerryCoffin yer, smart way of doing it, but not something we where told about back in first year.
 
@thecoshman At the risk of sounding old, believe me, it's still a lot nicer than the debugger I had available when I started out. I don't even remember the name (probably something brilliant like "db") but Control Data's debugger for Fortran IV was about as fun as getting teeth pulled...
 
12:20 AM
they give me happy gas when getting teeth pulled, so everything is very pretty
 
break though! that dam original library is fecking old and a new (c++) vesion can be downloaded! yay :D light for the morning
i'll call it quits for the night here then. Night all
 
Calling it quits for the day sounds like a nice idea...
 
@JamesMcNellis Doesn't it though -- unfortunately, I still have two reports that need editing before morning...
 
@JerryCoffin I decided to refactor some code today. Now I have to make it work again...
 
12:32 AM
@JamesMcNellis Oh, but James -- refactoring never breaks code! :-)
 
@JerryCoffin Of course not! I just figure it means the code was really broken in the first place; now the brokenness is just manifesting itself observably :-P
 
 
7 hours later…
7:32 AM
Post code inline if short; use codepad.org or ideone.com for longer code, and to run.
 
8:06 AM
morning :D
 
 
1 hour later…
9:09 AM
Hi. Slow day eh?
 
9:20 AM
s/day/night/
@GMan: I wonder if there's a canonical post about rvo for that
 
@GMan: Hm, good question. I haven't happened across one.
 
9:33 AM
anyone know why this would give a perf warning from the compiler:
bool is_int(const boost::any & operand)
	{
		return operand.type() == typeid(int);
	}
warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
 
that doesn't even make sense, where is an int converted to a bool?
surely msvc's type_info::operator== returns bool
 
I would hope so
I don't understand this warning... it seems a like it doesn't apply to this at all
 
Check and see. that would be awfully dumb
 
make clean and see if it reoccurs
however, if it is an incorrect return type on op==, there's nothing you can do about it: you clearly want to call op==
if make clean helps, you also need to fix your project dependencies, btw
 
how can I check what type_info::operator == returns?
 
9:39 AM
int main() { cout << typeid(typeid(int) == typeid(int)).name(); } // worst case :P
 
clean didn't make a difference
 
@tony: look at definition of typeid
in <typeinfo>
 
class type_info {
public:
_CRTIMP virtual ~type_info();
_CRTIMP int operator==(const type_info& rhs) const;
 
thats sooooo dumb MS!
 
thats what it says in typeinfo.h
 
9:41 AM
So the operator== returns an int
No .h, by the way.
 
strange eh..
 
None of the non-deprecated standard library headers have extensions.
 
ok
 
...except the deprecated C headers
 
but msvc still has headers with .h behind them
like when you create them in a project
 
9:43 AM
Those aren't standard headers. (@Roger What do you mean, I covered that...;) )
 
the no-.h convention used in the stdlib doesn't apply to other projects
 
You'll just need to do return (operand.type() == typeid(int)) != 0;
 
@GMan deprecated is still standard; cf. export in 0x
don't obfuscate the code
 
@Roger (I edited my old message, I'm sneaky and mean.)
 
disable the warning locally (msvc is particularly nice for that) if you must
oh, I see :)
 
9:44 AM
@Gman, yes that got rid of the warning
is it better to make a class with only public functions or a struct? this is just a utility type object
 
always use struct
 
@RogerPate thx :)
 
template<class T> struct Example { Example() : _answer(42) {} private: T _answer; };
 
Isn't that technically ill-formed since you never used the template parmeter?
 
eh?
 
9:48 AM
idk, I heard once upon a time declaring a template parameter and not using was invalid.
By potatoswatter I think.
 
though it'd be rather rare, I wasn't under the impression it was
 
Ah, just wondered if you knew. I still can't be arsed to look. :)
 
same
 
now I think my is_string version of the function will be harder to return an bool ...
bool is_string (const boost::any & operand)
	{
		return boost::any_cast<std::string>(&operand);
	}
 
try { ... } catch (boost::bad_any_cast&) { return false; } return true;
 
9:52 AM
@Tony: What do you mean?
 
why are you using two different ways of checking the type?
 
@RogerPate I think I have had this debate with you before, why ALWAYS STRUCT? In this case, yes a struct saves you writing public: but there should be no difference, just your opinion on which to use. Or am I still missing something about how structs are secretly different from class in more then just default access?
 
@RogerPate how else could I check if it is a string?
 
@thecoshman No, there's no language difference. His argument is more about consistency/convention.
 
with typeid(std::string)??
 
9:55 AM
@Tony Same way you checked for int.
 
template<class T> bool is(boost::any const& x) try { boost::any_cast<T>(x); return true; } catch (boost::bad_any_cast&) { return false; }
 
@GMan so surely saying "always struct" should be followed up with "by convention"
 
does boost::any_cast also handle base types? if so, typeid won't
 
@Tony But @Roger's is much better. If you find yourself repeating somethings, but only with differing types, you should be making a single template function instead.
 
@thecoshman my reasons why it is better haven't changed
 
9:56 AM
@RogerPate What do you mean?
 
@GMan indeed
 
@GMan: struct B {}; struct D : B {}; can I put a D into an any and get a B out?
 
@thecoshman That's to a different message.
 
@thecoshman: it also saves you writing public (no colon)
 
@Roger: Ah, no. It's strictly the same type. (It basically does if type() != typeid(Target), throw.)
Nope. :/ It's basically a void* that checks the type_info matches.
 
9:58 AM
@GMan: ah, thanks
 
template <typename T>
bool contains(const boost:::any& operand)
{
    return operand.type() == typeid(T);
}
 
@GMan, should put that template function in a class or struct or just global?
 
yeah, same interface, just implementation detail
I thought any_cast was smarter
 
Uni time ¬_¬
 
@Tony: why would you put it in a class?
 
9:59 AM
Nope. :/ It's basically a void* that checks the type_info matches.
 
@RogerPate sorry but my template knowledge is not as advanced, and it still confuses me at times
 
some languages require things to be in a class, even when it doesn't make sense; when you find yourself doing something for unknown reasons, just step back and ask "why?"
 
@RogerPate makes sense
when passing a const std::string& str to a constructor of a class, why can I not just do MyObject object("somestring") then?
 
You can.
 
stop using that compiler
 
10:05 AM
You're on 2003? Might just be a buggy compiler.
 
yes 2003
 
Yeah, just a broken compiler, twice in one night. :)
 
sorry, my mistake, its just using the wrong constructor overload it seems
 
lol, I cannot change compiler, else I will have to break part of my project
 
10:06 AM
:/
 
10:28 AM
Night \o
 
whats the best way to convert a const std::string to a std::string&
?
 
11:00 AM
@tony: why do you want to do that?
 
@RogerPate because my map contains a std::string and my function a reference to a string, however it seems the compiler looks upon this string in the map as a const string
 
map keys are const
does your function modify the string?
 
no the string itself is not modified, it is passed on
 
then the function should not take a non-const reference
0
A: How to pass objects to functions in C++?

Roger PateThere are several cases to consider. Parameter modified ("out" and "in/out" parameters) void modifies(T &param); // vs void modifies(T *param); This case is mostly about style: do you want the code to look like call(obj) or call(&obj)? However, there are two points where the differenc...

 
but string should be passed by ref or by value ?
 
11:12 AM
read the text under "Parameter not modified"
 
 
2 hours later…
12:50 PM
are hard-coded strings a bad sign in a code base?
 
 
1 hour later…
1:50 PM
Hey All, can anybody suggest a tool to identify unrequired archive files being referenced in makefiles?
I am working with a huge codebase of around 8 millions line of code and the makefiles are being passed around a lot . The component I work with refers to more than 300 archive files , of which I know some are not required. Is there a way for me to find all the archives which are being actually used and remove the rest?
 
2:46 PM
hi anybody iin
Mr. CoshMan
hullo
 
2:57 PM
hello
 
hi
I have a question
I am trying to call a .C funtion from a c++ file
and I am getting an error
here is the .C code
#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ContactPreservation.h"

char choice[10];

void userChoice (char *selection)
{


printf(selection);

strcpy(choice, selection);

}

char *passUserChoiceToSyncAgent()
{
return choice;
}


#ifdef __cplusplus
}
#endif
...
and here is c++ call
char *userSelection;

strcpy(userSelection,passUserChoiceToSyncAgent());
I am getting this error
"passUserChoiceToSyncAgent()", referenced from:
 
@BogusBoy yo
 
hey
thecosh
 
@BogusBoy sup B Boy?
 
@BogusBoy why don't you just port it to C++?
and use strncpy, not strcpy...
 
3:04 PM
that's ok
but what about the error
the function call
it's part of an iphone ipp
 
referenced from where??
 
referenced from c++ file
 
perhaps it cannot find the file
 
"passUserChoiceToSyncAgent()", referenced from:


CSyncAgent::InitClient(unsigned int)in libMO.a(SyncAgent.o)


ld: symbol(s) not found


collect2: ld returned 1 exit status
 
the C file
 
3:06 PM
imported the header
CSyncAgent is a class in c++ file and InitClient is a function of this class
 
so it can't find that function, not sure why
 
I am trying to call the .C function passUserSelectionToSyncAgent from within this function
 
I never programmed for Iphone
 
this exchange is happening b/w the .C and c++ file alone
nothing much to do with the iPhone code
theCosh
may be you can help
or who is the other person we have
Mr. James
 
 
2 hours later…
4:55 PM
jpegs are becoming a real pain the ass for me, do not like them >:(
 
5:09 PM
any one have any experience using libjpeg? Its proving to be really frustrating. I'm getting an error with in one of the standard functions, I think because libjpeg is built mainly to read data from a file, but I don't want to have to write my data to a file to then read it back out... or is there some fancy pants way I make a block of memory look like a file stream...?
 
5:28 PM
@thecoshman You can make libjpeg read from a custom data source
But I don't remember exactly how (old libraries are often a real pain to use)
 
5:43 PM
@Tomaka17 just a little bit
@Tomaka17 is it possible to make a block of memory look like an i/o stream, so that libjpeg can 'read' it as if it was reading a file?
 
Are we talking about the library from ijg.org ? This one can't read C++'s streams
 
@Tomaka17 That's the one, except I want it to read form memory, but I got a c++'ised version
which actually compiles in my application. I'm just having problems setting up the reading a jpeg that's in memory.
 
5:59 PM
@thecoshman Perhaps it would help if you told us exactly what "c++'ised version" you're using...
 
lol, yer may be :P
hang on
its failing in the reader header function, some where it tries to reset the error messages
 
6:41 PM
That seems to be using the original ijg API, which includes jpg_mem_src to use a memory buffer as a source.
 
sbi
(Please disregard me, I'm just lurking while I wait for my tests to run.)
Oops. I wish they'd test FF by loading multi-MB logfiles on a Hudson server. In 1 out of 5 cases his will crash FF.
Fortunately it reopens with all the 237 (or so) tabs reopening. It'd be a shame to lose them all.
 
7:11 PM
@JerryCoffin I can't see any reference to jpg_mem_src though... it sounds like the function I want to be using, but I don't where it is
 
Does anyone know a library for generation a GUID under C++?
and why is this lounge a memorial for Neil Butterworth? (if i may ask...)
 
@Tony: Poco has a UUID generator. Some people feel sad that he's left.
 
@StackedCrooked ok cool, ok
 
7:26 PM
@StackedCrooked Is there any reason why he left?
 
7:40 PM
@thecoshman Looking at its source, they seem to have removed it, though I've no idea why. I'd probably grab the un-modified source, grab that part, and see how much (if any) trouble is caused by putting it back in.
 
7:54 PM
Is there a trick to reading a string from a binary file? For some reason I'm getting an extra character
I'm expecting to get SCTR, but I'm getting SCTRÿ
hex value of the extra char is 01
 
8:06 PM
@Bocochoco There's no one "trick" -- you have to know how that particular file delineates the beginning/end of a string. Some do things C-style with a 0-byte to terminate the string. Others are Pascal-style with a byte (or two or four) before the data to tell how long it is.
 
I made the file in a hex editor. I think I just figured it out, I null terminated it char[4] = 0;
 
 
1 hour later…
9:10 PM
I think this is a step forward, my program actually runs now
 
I'm having problems with mine, converting from world space to local space, so my agents act weird.
 
9:35 PM
@Wolf, what are you coding?
 
9:57 PM
you know, I don't know if I love or hate MS right now... after nearly a week solid of arsing around with shitty libjpeg, I find the DX has a "make a texture from this file in memory" function ¬_¬ not a happy camper
 
when a class contains an STL container does the class need an explicit copy constructor or not?
 
sbi
@Tony No, not for the STL container.
 
and when the STL container has a struct inside it just with strings?
its not a pointer to the struct or anything
 
sbi
@Tony ...that struct needs to implement copy semantics anyway.
 
@sbi, you mean a copy constructor by that?
 
sbi
10:09 PM
@Tony What do you mean "string"? std::string? Fine. const char*? Uh oh.
The rule of three (also known as the Law of The Big Three or The Big Three) is a rule of thumb in C++ that claims that if a class defines one of the following it should probably explicitly define all three: *destructor *copy constructor *copy assignment operator These three functions are special member functions that are automatically created by the compiler if they are not explicitly declared by the programmer. If one of these had to be defined by the programmer, it means that the compiler-generated version does not fit the needs of the class in one case and it will probably not fit in t...
 
@sbi it has only std::string
 
@Tony Working on a game, 2D top-down shooter. I'm implementing some steering behaviors and building up my math library at the same time.
 
@Wolf, that sounds like a challenging task
I know from having looked into games dev a little bit, that it seems to have quite a lot of math...
:)
 
@Tony It can be, especially since I want to sell it, so it needs to be top quality. But the math behind it is not that hard and once you've done it once, you just copy/paste in the next project.
 
sbi
@Tony std::string is fine in that it manages its memory itself.
I think GMan recently formulated that again: A class should either manage one resource object or have several of such items as members. A class should never try to manage more than one resource objects.
3
std::string manages its resource (memory). So use it freely.
 
10:25 PM
@sbi thx
 
sbi
@Tony You're very welcome.
@BeeBand: What is it you wanted to ask?
 
sorry - no i was just wondering why the thread was called "neil butterworth" memorial and i thought this box was a search bar. so it looked like i was saying "neil butterworth" in a really wierd way.
so i deleted my post.
why did he leave? where's he gone?
 
sbi
10:42 PM
31
Q: Setting up a FAQ for the C++ tag

sbiA while ago Neil Butterworth, one of the most highly reputed people in the C++ tag (he has given so many good answers, that in the two months since he left, his defunct account has amassed >2000 rep from old answers), left here, obviously in frustration about Stackoverflow. I have since heard a f...

 
I see. It's a real shame he left... but I get it about the noise issue. I always search stackoverflow before asking a question - but sometimes, if you are new, it's hard to know what terms to search for exactly.
 
sbi
@BeeBand I'm not trying to blame anyone. I just want better tools to deal with the situation.
 
@sbi, yeah - it's a good idea. I worry about contributing to the noise! e.g. i asked a question about pure virtual functions recently - did a search before posting, and loads and loads of questions came up. but nothing specifically seemed to answer my question. However, its possible that if those answer were grouped somehow, or more structured...
then i might have found the asnwer without having to post.
 
sbi
@BeeBand Yep, that's the idea, basically.
Note, however, that there already is a C++ FAQ: parashift.com/c++-faq-lite Very worth to look at.
 
11:00 PM
It would take a very exhaustive and probably unpracticle guide to be able to cover all of these issues of programmnig language. I don't know how well a wiki could work, trying to give an exhaustive guide to using more or less every aspect c++, an epic task I admit, but one that more or less every one could benefit, from people want the first basics to those who really wish for some way of proving to their house mate that a struct really is the same as a class!
 
sbi
@thecoshman We don't need to be exhaustive. As I wrote in (at least) one of the comments, just the ability to quickly find that one perfect to link a duplicate to when closing it would be heaven-sent.
 
Which reminds me, can you use a struct with constructors, destructors, virtaul and pure virtual functions polymorphism, multiply inheritance etc? I am sure you can, but found some, admitadly old (2002), posts saying that a structs can't do this
 
sbi
@thecoshman IIUC, you're asking whether you can use a struct for that instead of a class?
 
@sbi I think I am proposing more or full on guide to EVERYTHING c++, every nuance in the book, there to be looked up when you have a question. it would need a very good search system so that even poorly phrased questions could get a decent set of 'suggested reading articles'
@sbi effectively yes.
 
sbi
If so, the answer is: Yes, you can. Basically, a class is nothing but a struct with a new name, its members being private by default (public in a struct), and the ability to use it instead of typename to declare template parameters.
 
11:04 PM
@sbi is theire ANYTHING a struct can't do but a class can. is it really just the public/private default access
 
sbi
@thecoshman There's nothing.
@thecoshman :58878 I think that's out of reach for what's available on SO. You need a book for that.
 
@sbi is there anything I can give to my friend to once and for all prove him wrong, that a class and a struct are the same
 
sbi
@thecoshman The standard document?
I'm not sure what you want to hear. If they claim a struct is not a class, they should provide evidence for that, no?
 
@sbi tried that... apparently out lectures 'erm... I don't know, suppose a class has more over head' response convinced him beyond the what the spec says... I may have to print out a copy and staple it to him. that's my point, I have to try and prove that lack of overhead from using a class rather then a struct, where as he claims there is this over head, that he can't (read will not) provide proof of
 
sbi
Well, if someone claims A, but cannot say why, and won't accept that A is wrong, that's called faith or believe. You can't argue with that.
 
sbi
11:21 PM
@thecoshman Well, I thought there would be something in D&E, but all I could find was this at the end of 3.5.1: >>...the "a class is a struct" notion is what has stopeed C++ from becoming...<< Basically, Stroustrup here sees a class is a struct as given. There might be a more explicit about that on his FAQ, though.
 
11:33 PM
"In C++, a structure is the same as a class except that its members are public by default." - msdn.microsoft.com/en-us/library/64973255(VS.80).aspx
Thats how Microsoft treats a class.
 

« first day (12 days earlier)      last day (4919 days later) »