Click here to Skip to main content
15,179,476 members

Comments by Aescleal (Top 200 by date)

Aescleal 11-Apr-16 7:35am View
   
Have a 5 but your results make me wonder where the questioner got his original Java timing of 76ms from...
Aescleal 11-Apr-16 6:13am View
   
From the unfocussed nature of the question I'd ask for your money back...
Aescleal 14-Mar-16 13:17pm View
   
Your solution doesn't look like C...
Aescleal 2-Mar-16 8:20am View
   
The 1990s called, they'd like their code back.

Seriously, take it outside and shoot it. Then burn the book you abstracted it from.
Aescleal 25-Feb-16 13:38pm View
   
It sounds like you've got a more severe error. OnDraw will only be called if a WM_PAINT is received by the window. Check that your code is not doing something brain damaged like calling OnDraw manually anywhere as that'll just end in tears.
Aescleal 23-Feb-16 7:00am View
   
You might want to see what the output is happens if someone enters 76.5
Aescleal 12-Feb-16 4:49am View
   
Thank you!
Aescleal 10-Feb-16 16:40pm View
   
Congratulations, it's 4 years late and not even C++...
Aescleal 10-Feb-16 4:06am View
   
I know, but he's not going to learn anything messing around with fill in the blanks rubbish like that. It might help someone that wants to do it seriously.
Aescleal 8-Feb-16 6:39am View
   
In that case don't mess about with explicit loops, use std::copy or memcpy if that's not fast enough.
Aescleal 3-Feb-16 16:03pm View
   
Have 5 for the allusion.
Aescleal 31-Jan-16 13:26pm View
   
+5 - that sort of code was described by Scott Myers as C++'s most vexing parse.
Aescleal 27-Jan-16 4:24am View
   
Wish I could give you some points for this - this is an aspect of C++ I've never considered, thanks for expanding my mind today!
Aescleal 26-Jan-16 9:29am View
   
C++ is not JavaScript... This sort of code is the sort of thing an experienced JS programmer would turn out but in C++ the class nesting is essentially overkill and doesn't do anything that a pair of implementation classes in an anonymous namespace wouldn't.

I wouldn't start trying to use code like this until you know why you want to do and that there's no cleaner solution. Have you ever considered using a far simpler design where you don't actually use nested classes? One major design flaw with this sort of "virtual constructor" is that you've prevented yourself creating an instance of your implementation class without using the factory which makes testing far more tedious than it needs to be.
Aescleal 22-Jan-16 7:29am View
   
The thing is there isn't a return value - there's no return statement. There's nothing telling the compiler "hands off!" on whatever mechanism it uses for returning values. There's nothing saying "propagate the value returned from the recursive call."

As a concrete example: If you have an architecture that uses a block of memory to hold parameters and return values there's nothing in that second branch of code that will update the caller's parameter/return block with the callee's return value. It'll end up with the same value you had before and the function essentially becomes:

int f( int a )
{
return a;
}

and you've got different output.
Aescleal 22-Jan-16 4:35am View
   
It's a bit daft to say that every compiler/OS/processor combination on the planet will return zero. Having used a compiler that tried executing nethack when it saw a #pragma I wouldn't put it past some witty compiler author to say "sod the world, I'm going to set all the volatile registers to random junk before I do an implicit return." I can even see a point at which that'd be useful if the junk was deterministic - it might help detect situations where someone's trying to use an undefined return value and not using -Wx.
Aescleal 21-Jan-16 15:23pm View
   
Looking at the questions you've been asking you're going in the wrong direction - you stopped using a std::vector and replaced it with something that'll leak like a sieve. And you're really complicating your implementation by using packed BCD arithmetic - if you want that I'd suggest using a language that directly supports it like COBOL. Using packed BCD makes all your arithmetic operations a lot more clunky then they should be and it takes more memory to store an integer of a given size.

For your addition assignment operator (and actually any assignment operator) you should return a reference to *this otherwise chained assignment won't work. And you get an extra copy with a bonus memory leak.
Aescleal 19-Jan-16 4:43am View
   
Before messing about with low level memory management try asking yourself the following questions (and this is just about the include file, it doesn't even look at the implementation file):

1) Why doesn't this compile?

const Mint a, b;

bool c = a < b;

2) What happens when you execute the following code?

Mint a("1234567890");

Mint b = a;
Mint c;
c = b;

3) How would using a vector solve all the problems in 2) and simplify all your code?

Once you understand that lot and fix the problems then come back and ask again.
Aescleal 18-Jan-16 7:34am View
   
Cool, thanks! I'd be tempted to just resize the vector after assigning the strings rather than preallocating the strings if making the vector a certain size was important but it's interesting to see the similarities rather than differences.
Aescleal 18-Jan-16 4:09am View
   
And I've just noticed the bug - managed to replace the max with a min, thanks for highlighting it!
Aescleal 18-Jan-16 4:03am View
   
Sorry you found my language offensive - all I can do is apologise to you,

Ash
Aescleal 18-Jan-16 3:59am View
   
I did test the code, quite thoroughly - I omitted the full tests as they weren't going to add anything to the conversation. However it was early in the morning and if you've got a breaking test case I'd love to see it so I can correct it.
Aescleal 18-Jan-16 1:21am View
   
This code looks like someone having a mental masturbation session - obfuscated type and variable names and a complex implementation with no description of what it's trying to do. The first rule of optimisation is find an algorithm that does what you want with lower complexity but as the code's not easily readable, we can't tell what it's supposed to do to suggest something simpler.
Aescleal 14-Jan-16 15:57pm View
   
Is this a course on C++? If it is ask for your money back - the structure and code you've written here are in C not C++ and if you're trying to learn C++ you're being lead in a totally inappropriate direction.
Aescleal 13-Jan-16 9:37am View
   
I'd disagree in the general case: You don't need types checked at initialisation time, you need them checked when they're used. I'd contend that explicit typing often makes code far harder to read (the type of a declaration is often longer than the expression it's initialised from) while implicit typing removes the need for long lists of typedefs. As an example consider what std::find returns when operating on an array of lists of unique pointers to widgets. And all the ways you can write the declaration of the return type using the typedefs declared by vector, list and unique_ptr.

This is doubly true (as in your case) when all you're using the variable for is a simple alias - you could have used pDC->m_hDC everywhere you used verylongnameforadevicecontext. If you keep your functions short your initialisations will never be far away from their usage and if it turns out that the type of a variable is not what you thought it was it means that whatever you used to initialise it wasn't quite what you thought it was.

And really you never want to use explicit type casting - except in some rare cases (low level bit fiddling/hardware interfaces) - in well designed code. Explicit type casting in C++ is usually a sign that you're mangling the intent of an interface and the code you're calling is trying to tell you something that you're avoiding.
Aescleal 13-Jan-16 6:10am View
   
The rule is don't change the size of a CArray after an initial SetSize (implied or otherwise) with objects that have a non-trivial copy constructor. Have a look at the source code and you'll see the problem.

Actually the rule should be don't use collection classes written by a bunch of C programmers that prefer bit fiddling to making their code robust...
Aescleal 12-Jan-16 17:26pm View
   
Does the code you've presented work when it's the only code in the program? i.e. wrap it in int main() with the relevant includes and see what happens.

What compiler are you using?

Are there any weird and wonderful macros kicking about that might confuse things (e.g. MS are very fond of redefining new in MFC in debug versions)?

Does adding an explicit copy constructor and assignment operator in the contained classes do anything?

Have you read the source code for CArray to see if you can get a handle on what's happening? (It's ghastly BTW)
Aescleal 9-Jan-16 2:32am View
   
Give us a few more clues about what API you're trying to use. We can guess that source and destination for something called encryptfile would be pathnames but if they are why aren't they const? Likewise what's the point of KeyBlob? Presumably it's a lump of memory containing the crypto key but then you seem to expect something to happen when you call encrypt to set that.

So give us a few more details and someone might be able to give you a decent answer rather than just speculating.
Aescleal 2-Jan-16 5:15am View
   
If you want it to be a member make the function const.
Aescleal 2-Jan-16 1:15am View
   
This doesn't add to the conversation at all. Advocating using a Microsoft specific function (sscan_f) to do something the original poster can already do (he says in the question he can read his file into a QT hashmap) under Linux is not a lot of use.

As an aside your file handling is way overcomplicated. All the guff with the ifstream at the beginning could be replaced by a single line and there's no need to close a stream unless you're going to reattach it to a different file at some point.
Aescleal 28-Dec-15 23:57pm View
   
What it means is if you've paid to do a course that's supposed to teach you how to program in C++ then you're not being taught very well. The implementation instructions look more appropriate for a course in C programming or the way C++. It's advocating a functional decomposition and ignoring all the bits of C++ that make that approach rather redundant.
Aescleal 28-Dec-15 23:07pm View
   
If this is part of a course designed to teach you C++ then I'd recommend you demand your money back. Learning to program in the style advocated in this assignment is not going to do you a lot of good in the long run.
Aescleal 28-Dec-15 21:04pm View
   
The questioner didn't say it was a requirement - he just asked why the compiler gave him an error when he did it.
Aescleal 27-Dec-15 6:53am View
   
Hi Mr. Downvoter,

I like knowing where I've messed up or told people incorrect things. So if I've made a mistake, provided some level of misinformation or otherwise said something wrong could you please tell me so I either can correct this answer, explain why I disagree with you to the original poster and generally get better at what I do.

Thanks,

Ash
Aescleal 26-Dec-15 14:54pm View
   
If you're going to program like it's 1993 you could at least make sure your code handles value semantics properly.
Aescleal 13-Jan-15 11:58am View
   
Maybe a more direct way of saying it would be:

int *p = malloc( n * sizeof(int) );

but seeing as the expression *p has a type of int then:

int *p = malloc( n * sizeof *p );

is effectively the same expression.
Aescleal 13-Jan-15 11:48am View
   
sizeof *p is the size of whatever p is pointing at.
Aescleal 13-Jan-15 9:37am View
   
We batch a large chunk of commands and then (a bit naughtily) do almost everything in the device driver's interrupt handler in page-locked memory. The turn around is very quick and we've never lost data because of it.

Video and audio drivers work batch a large chunk of data to be rendered and do the display/playback by passing the data off to dedicated co-processors so they don't have to quite as cavalier with windows architecture.
Aescleal 12-Jan-15 23:17pm View
   
You use the device driver to replace the real time OS. Your main app makes the decisions, the device driver carries them out in a timely fashion. Generally you batch or script the decisions and pass them to the driver in one fell swoop so you don't have to flit in and out of user mode - you do far more in the driver's interrupt handler than would normally be tasteful, Presumably that's why your foam cutter software locks up the system when its doing its thing.
Aescleal 12-Jan-15 23:07pm View
   
intime is apparently pretty good - the company I work for used it but wrote their own solution for a limited subset of hardware to cut out the licensing fees. Caveat: I don't have any experience of it, just the code that replaced it!
Aescleal 12-Jan-15 16:28pm View
   
Out of the box it doesn't provide any real time facilities, but if you're willing to dive in at the device driver level you can handle the events you're interested with a maximum latency.
Aescleal 12-Jan-15 11:20am View
   
Reason for my vote of 1 \n There is no need for finally in C - it's got destructors. Use RAII and the tools and in the standard library and any need for finally disappears up it's own bottom.
Aescleal 7-Jan-15 15:44pm View
   
It popped to the top of recent questions, should have checked the date :-(
Aescleal 23-Dec-14 13:08pm View
   
If I were you I'd ask for a refund on your course fees. While I've missed the context of the question whoever set the question is showing you how to do things in a way that makes my toes curl - and not in a good way.
Aescleal 10-Dec-14 13:13pm View
   
Shame you've got what's basic completely wrong.

Turbo C was a great little IDE and compiler back in the early 90s but it's completely useless now. You're doing your students no favours teaching them how to use it or all the bad habits they'll have to get into to use it effectively. If you think that C programming with 2 different pointer sizes, 4 variants of malloc and requiring the use of assembly language and esoteric command line switches to actually get large programs to work is "basic" then I've got a bridge you might be interested in buying.
Aescleal 10-Dec-14 11:42am View
   
The 1990s called, they'd like their education back...

You're using a 22 year old compiler produced 7 years before the last completed language standard on a baroque architecture to create an application that doesn't play to the strengths of the language. What next? Device drivers for an IBM/360 in Fortran 66?

Teach them how to program on a Linux box if you want something that's cheap.
Aescleal 9-Dec-14 11:30am View
   
I think there's probably something a bit weird with his measurements as well. My rather naff i5 can do a partial sum of 20 million ints in about 80ms. Sorting the data takes ages but halves the time taken to do the partial sum. Even better is partioning the data into two ranges and then just summing the range you want - that takes about 4ms.
Aescleal 26-Nov-14 5:24am View
   
As well as the answer below look at using std::string or std::vector instead of raw character pointers. They're a lot easier to get right at the cost of not a lot of performance.

Additionally remember that main is int main() - void main() is only supported on non-hosted systems. Also get into the habit of initialising all your variables when you declare them, it's bound to save you some grief at some point in your learning or subsequent career.
Aescleal 26-Nov-14 5:19am View
   
I can't really comment on this as I haven't done it in nearly 20 years. Writing a CGI program might be a good way to go if you can work out how to do it. Your XML stream will effectively come in as either a command line argument or stdin. You might have to relax security on your webserver though as I can't imagine most webservers want arbitrary code to be run on the host.
Aescleal 25-Nov-14 5:27am View
   
I wouldn't use shared_ptr for this sort of thing unless you know the performance implications of what you're up to. std::vector is almost always a better choice when you need a contiguous block of memory of a size determined at runtime.

Basically you have to balance the cost of copying the shared pointer against the cost of initialising the vector. The only way you're going to find that out is test them both in your use case and measure the performance.
Aescleal 21-Nov-14 8:27am View
   
I'd suggest getting a new professor - unless there's something very subtle he's trying to demonstrate he's not got a clue about how to use C++
Aescleal 20-Nov-14 14:00pm View
   
Which won't work on VC++2008...
Aescleal 20-Nov-14 7:49am View
   
So Mr. Downvoter - what's wrong with the answer I've given here? If it was factually incorrect (i.e. it's not the copying of ifstream that's causing the problem) I'd like to know what's wrong so I don't make the same sort of mistakes in my code as the poster. If the advice I've given the poster is incorrect (get some understanding of how and why you can't copy construct an ifstream and why you have to use a reference) I'd also like to know so I give better advice in the future.

Likewise I'm sure Karsten would like some fuller explanation as to what's wrong with his answer.
Aescleal 20-Nov-14 7:49am View
   
+5ed to compensate for whoever hit you with a 1. I don't mind univoters if they tell you why...
Aescleal 12-Nov-14 11:32am View
   
Don't be so sensitive - it looks like you've got a chip on your shoulder. I've just noticed that loads of Indian questioners use the form:

fstream str;
str.open( ... );

rather than the idiomatic:

fstream str( filename );

It doesn't seem as prevalent in European or US students but that might be because (a) the language is rarely taught outside of games programming degrees in Europe and the US and (b) less European and US students ask for help on here.

So a free bit of advice: Use the constructor form whenever you want to open a stream but be careful of the second, defaulted parameter - it often doesn't do what you want. If you do it'll make your code a lot easier to read in the long run and won't look so naive.
Aescleal 12-Nov-14 8:20am View
   
My 5...

As a completely separate aside: I've noticed that when questioners use fstreams they seem to open them separately from constructing them. Maybe it's me but that sounds like it's completely barmy. Maybe there's a tradition of crap C++ teaching in India which encourages this.
Aescleal 10-Nov-14 11:39am View
   
One of the many reasons why using things like std::copy and std::for_each can be so much better than fiddling about with manual loops...
Aescleal 6-Nov-14 6:11am View
   
Bugger, I missed the ="" artifact when I cut and pasted the code in. Sorry about that!
Aescleal 29-Oct-14 6:38am View
   
There's enough rubbish C++ in the world - please don't add to it, even if you're being ironic.
Aescleal 28-Oct-14 10:22am View
   
Have a crack with brute force and ignorance then others on here can show you some tricks that'll show you how to solve it using some language tricks.
Aescleal 21-Oct-14 8:21am View
   
Thankyou - nice to know I'm appreciated when I stick my head over the parapet every once in a while :-)
Aescleal 21-Oct-14 7:13am View
   
It's not the compiler that's complaining - it's the linker. The OP is comparing the behaviour of a constant with a mutable pointer to a constant.
Aescleal 21-Oct-14 7:11am View
   
Your English is a bit clumsy but it looks like you've been researching what's supposed to happen with const objects so you don't deserve the downvotes.
Aescleal 2-Oct-14 12:49pm View
   
Just a quick note: In C++ 11 you can use decltype to recover the type of str in the second code block if you need its' type somewhere else:

decltype(str) other( str );

will create another structure with the same binary layout as str and copy str into it.

edit: Forgot the greater than/less than tags to show angle brackets..
edited again: Ballsed up - decltype uses ordinary parenthesis....aaaarrrgggg
Aescleal 22-May-14 10:03am View
   
T t{}; means "t is a T that's default initialised."

It's not gibberish - it's standard C++.
Aescleal 2-Feb-14 0:04am View
   
While you can override CWnd::WindowProc I wouldn't. If you do you loose support for things like message reflection which are particularly important for controls (the control itself can handle WM_COMMAND and WM_NOTIFY messages without needing the collusion of it's parent window). If you derive a new class from whatever MFC wrapper exists for the control you tend to write less code and don't have to fiddle around cracking messages or managing storage and forwardong of messages to the control's original window procedure. MFC does all that for you.
Aescleal 1-Feb-14 18:10pm View
   
How's anything subclassed in C++? You derive a new class from the control you want to customise.
Aescleal 31-Jan-14 14:13pm View
   
Just seen the tit edited the question to add a default constructor. Why the muppet didn't ask a completely new question is beyond me...

Changed the 1 I gave you to a 5. Sorry about that...
Aescleal 31-Jan-14 14:12pm View
   
Unless the questioner has edited the question (I didn't check) there is a default constructor. The problem is he/she/it's not creating an object in main, they're declaring a function.
Aescleal 31-Jan-14 14:09pm View
   
It's not a compile time error 'cause what you've written is valid C++, it just doesn't do what you thought it should.

You're declaring a function - you're saying to the compiler "Somewhere there's a function called obj which takes no parameters and returns an X. Don't worry if I call it, the linker will sort it out."
Aescleal 31-Jan-14 14:05pm View
   
Glad it helped!
Aescleal 23-Jan-14 23:35pm View
   
If you're learning C++ (looking at your code and the way it won't work I assume you are) you might want to get yourself a compiler that's not some relic of the Dark Ages. Grab a copy of the latest version of g++ your OS can handle or Visual C++ if you use Windows.
Aescleal 12-Dec-13 17:37pm View
   
Hi Mr. Univoter, any clue as to what's factually incorrect with my answer? I'd like to know so I can improve my practice in the future. I don't indulge in tit-for-tat down voting so please don't worry about some sort of petty retaliation.

Ash
Aescleal 12-Dec-13 7:13am View
   
The first thing you describe is "a function that returns a pointer to int," it's not a function pointer or a pointer to function (which are the same thing).
Aescleal 9-Dec-13 4:35am View
   
Not a clue either - looks like the server's complaining about extra or unexpected whitespace. That might be you're sending an unexpected character encoding or even something like the server's XML parser not understanding the space between your request's opening < and tag name.
Aescleal 6-Dec-13 3:56am View
   
If you use void main() your code isn't guaranteed to compile or do what you want. So don't. Ever.
Aescleal 5-Dec-13 12:03pm View
   
Nothing like test driven development to get results quickly!
Aescleal 22-Nov-13 10:06am View
   
Take note people, this is the comedy you get when you try and pretend that C++ is Javascript.

At least I assume that's what the author of the code's trying for 'cause it's pretty weird otherwise.
Aescleal 20-Nov-13 0:28am View
   
Hi Mr. Uni-voter. Any clues as to why you dropped a 1 on me? I'd like to know so I can either take your points on board and amend my answer or have an informative comment next to my answer so other people can see the context of any disagreement.

Thanks!

Ash
Aescleal 14-Nov-13 14:53pm View
   
Average should not be set. It's completely logically bent to even suggest that. It's a derived quantity from the rest of the object's state.
Aescleal 14-Nov-13 14:47pm View
   
I can't comment on C# as I don't use the language, but a getters/setters style of programming takes the focus away from the behaviour of objects and places it more on attributes of the object. Instead of telling an object to walk to John O'Groats and letting it get on with it you ask it it's shoe size and calculate the number of steps.

Setters make it far harder to maintain a class's invariant (if you can twiddle small chunks of an object independently it's harder to check the object's state is valid) and encourages the ghastly practice of "constructor-followed-by-initialisation-function-cause-we-dont-understand-exceptions" that pervades certain arenas of software development.
Aescleal 10-Nov-13 14:52pm View
   
Invitation accepted!
Aescleal 8-Nov-13 16:29pm View
   
You might like to just present the bit of code you're having trouble with rather than giving us a shed load of loops with more nesting than an orgy of randy seagulls.
Aescleal 7-Nov-13 11:59am View
   
Streams don't know about files so I'd go for std::remove and std::rename, unless you've got access to boost::filesystem.
Aescleal 7-Nov-13 11:56am View
   
"much, much faster"? Really? I tested the code on Microsoft's x86 compiler (every version from 1.52 to 2010) and divison/modulus was within 1% of the performance of the shift. I also tested on gcc 3.3, 4.1 and 4.8 for both x86 and ARM and there was no difference. The assembler generated was just about identical between compilers as well. Performance didn't change much when I converted the vector to a built in array in case the dastardly STL implementation was slowing things down and reducing the impact of me begging the compiler to do its job properly.

Unrolling the loop didn't do anything for the speed either.

Even when using an unoptimised version the compilers couldn't stop themselves and were doing shifts instead of division (MS's still did a div for the modulo though). And the performance wasn't that different from the optimised version.

So I'll trust my compilers to convert from the direct statement of an algorithm to whatever arcana the silicon wants.

The moral of this story is messing about with premature optimisation is pointless unless you know you have a performance issue. Write your code to represent what you want it to do and if that's not fast enough then start thinking about micro-optimisations.

[edit for wonky English...]
Aescleal 7-Nov-13 6:38am View
   
Have a 5 (at least when I work out how to change the 4 I clicked on by accident just now) to balance the 1 someone else dispensed. While I wouldn't have done it this way it's a valid alternative to the shift and mask solutions proposed before it.
Aescleal 6-Nov-13 6:09am View
   
Ah, misread that in your initial question. Could be network latency causing the problem but saying that is about as much help as a chocolate fireguard. As a first workaround I'd suggest retrying N times with a pause between the tries but that's really ugly.

Hope you get to the bottom of it and sorry I wasn't more help.

Ash
Aescleal 6-Nov-13 4:30am View
   
As well as following Garth's advice to split things up a bit and include some error checking look at using the string range constructor, std::string::substr and operator+( const string &, const str &), they might make your code slightly less WTFish to read!

Don't be afraid of local variables, they can make things far easier to read and won't slow your code down in the general case.
Aescleal 31-Oct-13 4:23am View
   
What the previous commentators said plus are you using C or C++?
Aescleal 30-Oct-13 4:33am View
   
Why are you using pointers, dynamic memory allocation and raw character arrays when std::vector and std::string would make your life a lot easier? You're writing too much low level code for the scale of the problem.
Aescleal 25-Oct-13 17:39pm View
   
While the answer's sort of correctish that code isn't C++ - see Griff's for the real thing.
Aescleal 25-Oct-13 8:13am View
   
Deleted
Are you using a decent C++ compiler? The fact it tolerates void main() suggests that perhaps it's not standard in other ways as well.
Aescleal 12-Jul-12 5:14am View
   
Hi, thanks for the reply, it was much appreciated.

My reasoning for my answer was there's often too much emphasis on using tools after a problem's arisen rather than stopping it happen in the first place.

Your point that if you're using a third party library without source or which you can't otherwise modify then tools are the only way to go was really well made and something I completely missed.

Again, thanks for being the first person to reply to one of my messages asking for clarification - with feedback like this it's worth getting 1s once in a while!
Aescleal 11-Jul-12 1:54am View
   
Have a 5 to balance out whoever gave you a 1 - this seems like a legit enquiry to me as formatted I/O is a bit of a bugger to get your head around in C or C++.
Aescleal 10-Jul-12 12:37pm View
   
Deleted
I did write an extensive reply but this sodding editor swallowed it. Anyway, thanks for the 5 and just to compare your experience with mine I've used streams almost exclusively since 1999 and all the projects I've worked on since 2004 have used them.
Aescleal 10-Jul-12 12:36pm View
   
Just to provide a bit of balance (thanks for the 5 BTW)...

- I've personally used streams almost exclusively for I/O since 1999
- Every project I've worked on since 2004 has used them extensively (even in code to control hard disks, games, security, futures trading)
- They work on just about any hosted environment (including modern games consoles) and a fair number of embedded ones
- They're a superb abstraction when you have to substitute I/O facilities when unit testing
- They're incredibly customisable; add boost and it becomes trivial
- Very little chance of making a type snafu

About the only downside is that their syntax is a bit cumbersome. And as for operator overloading these days I tend to think the abuse is using the insertion and extraction operators for bit shifting.
Aescleal 10-Jul-12 10:29am View
   
Your question had C and C++ tags, might be an idea in future to check them before posting. I'll leave the solution here though 'cause it provides a contrast between the C and ++ style and it might help someone else in the future.
Aescleal 10-Jul-12 10:24am View
   
Hello Mr. Univoter. Here's my standard question to the likes of you. Can you please tell me why you down voted me so I can either:

- Remove any technical inaccuracies in my answer (I like learning where I get things wrong, it improves my C++ practice)

- Improve the presentation of my answer if it's not clear

- Leave my answer unchanged along with your comment so other people can make up their own minds about whether your criticism and my answer are relevant/timely/appropriate.

Thanks!

PS: I don't do tit-for-tat uni-voting so please don't worry about your rep if you stick your head above the parapet, I really want to know.
Aescleal 30-Jun-12 13:45pm View
   
ACE is a good way of abstracting networking but it's not that good at explaining how it works. I get the feeling the questioner doesn't want to abstract sockets as much as learn how to implement them.

The book you've recommended is pretty good when you've got your head around ACE but I've found "The ACE Programmer's Guide: Practical Design Patterns for Network and Systems Programming" a better starting point for the beginner.
Aescleal 30-Jun-12 13:39pm View
   
Using the standard library isn't an optional extra in C++. Unfortunately most lecturers and textbooks are idiots/written by idiots and they think that you have to learn all the unsafe bits should be taught first as they're somehow more fundamental. If they didn't tell you about arrays and pointers you could get confident with the language before banging your head against them.

Anyway, rant over, good luck in whatever you're using this code for.
Aescleal 30-Jun-12 13:35pm View
   
It's not so much "learning to think in STL" as getting your head around the standard library. A good way in is to say: "Okay, I'm not writing another loop." Even if you fail you'll start to get a handle on it.

Of course I wish my co-workers in the games industry thought the same way.
Aescleal 30-Jun-12 9:01am View
   
Sorry old son, I can't share that opion. MFC might have been good 20 years ago but these days it's a complete behemoth that should have been put down.

If you'd like to revise your answer to something like: "Look at MFC, it can speed up the development process for windows apps and I really enjoy using it" then I'll crank up my 1 to a 4 or 5.
Aescleal 29-Jun-12 14:44pm View
   
Perhaps if you programmed it in C++ rather than some hybrid of C you might have fewer problems. If I were you I'd demand my course fees back - whoever taught you to program in this style doesn't deserve the title of lecturer or teacher.
Aescleal 28-Jun-12 6:20am View
   
The amount of data you're using will exceed the amount of level 1 cache on most processors. In this case you want to access variables sequentially. It'll be faster and it's a more natural way of doing it for both the programmer and the processor. It also avoids the cache wrecking effects of thread switches as well.

Having said all that, if performance bothers you then measure it, that's the only way to know for sure.
Aescleal 28-Jun-12 6:19am View
   
No probs, have a 5 for the revised answer
Aescleal 28-Jun-12 4:22am View
   
Deleted
The amount of data you're using will exceed the amount of level 1 cache on most processors. In this case you want to access variables sequentially. It'll be faster and it's a more natural way of doing it for both the programmer and the processor. It also avoids the cache wrecking effects of thread switches as well.

Having said all that, if performance bothers you then measure it, that's the only way to know for sure.
Aescleal 28-Jun-12 4:08am View
   
They're not sub ns by any stretch of the imagination - even if something's in the level 1 cache then it's going to take several nanoseconds to read. Writing will be faster if you've got a writeback cache although multiple cores/processors slow that down. If it's not in any cache (which is very likely if you've just allocated a block of it) then it's going to take at least 40ns to read.

Sequential access is at least 10 times as fast as random access as it uses cache lines that are already filled.
Aescleal 23-Jun-12 15:10pm View
   
Couldn't see it in the standard, but I only had a quick scan for __STDC__. I haven't got an electronic copy handy so I'll defer to someone with a PDF that can look properly.
Aescleal 23-Jun-12 13:18pm View
   
I've just tested __STDC__ on every version of Visual C++ since 1997 and they all supported the macro. Are you sure you're not compiling your files as C++ or as C without /Za?

AFAIK C++98 doesn't specify __STDC__ so that might be your problem.
Aescleal 14-Jun-12 3:26am View
   
Sorry, I'm guilty of assuming all software engineers are men, apart from my wife that is so I've got less excuse than most!
Aescleal 14-Jun-12 2:50am View
   
Ho do you free it? You've overwritten the pointer that contains the address of the block. Actually it looks like you've done the same thing with the block R2 pointed to as well.
Aescleal 14-Jun-12 2:49am View
   
Deleted
Ho do you free it? You've overwritten the pointer that contains the address of the block. Actually it looks like you've done the same thing with the block R2 pointed to as well.
Aescleal 14-Jun-12 1:18am View
   
So do I, but a fair amount of example code uses direct calls and it's easy to pick up the habit.
Aescleal 13-Jun-12 22:48pm View
   
Hi Mr. Univoter, any chance you can tell me why you voted me down? This is so I can either/or:

- improve my answer and perhaps learn how to express myself better next time
- learn something
- disagree with you and say why and let other people make up their mind

I don't do tit for tat univoting so don't let that stand in your way!

Ash
Aescleal 13-Jun-12 14:01pm View
   
Ninjad by a minute :-)
Aescleal 13-Jun-12 8:51am View
   
I can see what he meant - he was assuming Win32 using something like MFC. Trouble is he left out a load of the details - i.e. either having to handle WM_COMMAND in the dialogue, reflecting messages back into the controls OR subclassing a raw control. None of which are trivial the first time you try it.
Aescleal 13-Jun-12 8:47am View
   
I've seen it happen in two places in MFC apps:

- to avoid calling CWnd::SendMessage
- derived class handlers calling base class handlers

Conceptually the first one may seem a bit bent but it's the same as sending a window a message - without the whole sending a window a message thing. The second one is essentially the same as subclassing a Win32 window, again without doing the window subclassing thing.
Aescleal 12-Jun-12 19:26pm View
   
That's worth a 5 any day of the week!
Aescleal 12-Jun-12 10:19am View
   
Gave you a 4 as you didn't mention the DDX functions which are the reason UpdateData works.
Aescleal 8-Jun-12 9:13am View
   
You don't like reading error messages do you?

The compiler is saying:

"You're trying to call LoadLibraryW which as it's first parameter wants a pointer to an array of wide characters. You're sending me an array of narrow characters. Sort your life out."

Now you might be thinking, "Huh? I don't call LoadLibraryW, I call LoadLibrary!"

However if you go to where LoadLibrary is defined you'll end up at a macro that defines LoadLibrary as LoadLibraryW if a macro (I think it's _UNICODE) is defined.

You've got several options here...

- Get rid of the _UNICODE define. LoadLibrary will resolve to LoadLibraryA and your call will work
- Use L"I am a string" everywhere you see "I am a string"
- Use yet another Microsoft character macro - instead of using "I am a string" use _T("I am a string")
- Probably some more I haven't thought of

Anyway, this is really an answer to another question. There are several articles on how to use UNICODE in Windows apps floating around on code project, have a hunt for them and they'll describe it in more detail.
Aescleal 8-Jun-12 4:25am View
   
Ah, right. That'll teach me to not read stuff properly. Sorry about that - I missed the first point you made to SA - "Unexpected catches the exception at the point that it's first incorrectly propagated." Doh.
Aescleal 8-Jun-12 4:23am View
   
I have a sneaking suspicion that MS will leave exception specifications as long as possible before implementing them. They're a deprecated feature in the new standard and no compiler of there's to date implements much of the old spec. Also Herb Sutter (one of MS's compiler architects) is a fairly vocal critic of them saying that they don't do what programmers expect them to do - either in terms of allowing more optimisations or doing static analysis of what's thrown.
Aescleal 8-Jun-12 4:04am View
   
Deleted
If I were MS I wouldn't implement exception specifications. They're a deprecated feature in the new standard and no compiler to date implement much of the old spec. Also Herb Sutter (one of MS's compiler architects) is a fairly vocal critic of them saying that they don't do what programmers expect them to do.
Aescleal 8-Jun-12 4:00am View
   
The big problem with the question is that whoever asked it didn't specify what a database is. When it comes down to it most relational databases are just vast arrays of data and the metadata (schemas/indices) describing them. However something like the Berkeley DB is also called a database and that's a map of key/value pairs. Microsoft use the word database all over the shop, completely willy nilly.

So it might be an idea to ask your lecturer exactly what he means by database. Depending on his definition it might preclude doing certain things in C++.
Aescleal 7-Jun-12 17:28pm View
   
Why would you? Not sure about all compilers but the two I know about handle exceptions on a different stack to the one they get thrown on - it's a bit hard (but probably not impossible) to unwind the stack while it's in use.
Aescleal 7-Jun-12 9:36am View
   
It doesn't show you anything - you know nothing about the context in which it's called. All you know is that a function tried throwing something that wasn't in the exception specification.
Aescleal 7-Jun-12 5:50am View
   
It looks like it would work fairly well. The only point I'd make is that protected members of a class generally set alarm bells off. Protected is for implementation inheritance which has the problem of tightly coupling classes together. So be careful if you end up with inheritance hierarchies deeper than one or two levels - they can bite. My career still has the teeth marks from some attempts at using implementation inheritance.

One thing I didn't mentioned yesterday and probably should have - you could have done something similar with a std::vector. Initialise one outside of the class and hold it as a const member. However if you want the memory for the array to be part of the object (for whatever reason, I don't want to know, it might be perverse and horrible!) then you have to use a proxy.
Aescleal 6-Jun-12 10:37am View
   
Another option to loading the library and doing the whole "get proc address boogy" is to use the same information to write a header and DEF file for the DLL and then use lib /def (IIRC) to create an import library.

If there's only a few functions you might as well loads the thing manually, but when you're trying to load something like NTDLL with a couple of hundred functions it becomes a bit of a swine :-).
Aescleal 5-Jun-12 3:30am View
   
The reason there are loads of functions is to make unit testing far easier - the functions are defined almost in the order I wrote them. I didn't include the tests as they rely on a C++ unit test framework and defeated the idea of the question being for C.
Aescleal 5-Jun-12 3:28am View
   
Why 26? How soon are the number of characters in the roman alphabet going to change? They haven't changed sine the middle ages as far as I know... It's a bit like #define ONE 1, completely pointless. Maybe the variable name is incorrect - perhaps it should be capital_letter_elimination table or I could have used a typedef to make it clearer...

For the reasons there are loads of functions see the original description and the reply to nv3.
Aescleal 5-Jun-12 3:25am View
   
The original poster only supplied one test case and it just had capitals in it. I suppose I could have gone the extreme programming route and just copied "HLL" to the destination but that would have been rather trivial.

Handling UCS 2 characters could be done in the same way, the full character set only occupies 128K which isn't a lot by modern standards, especially on 64 bit machine.
Aescleal 4-Jun-12 6:05am View
   
I couldn't with any conscience give you anything more than a 1 for this - you used gets which means any idiot can crash the function by typing in loads of characters - i.e. just leaning on the keyboard.
Aescleal 4-Jun-12 6:04am View
   
Someone's missed the point here...
Aescleal 4-Jun-12 5:59am View
   
Doesn't strike me as being that brute force and quite a direct method. However (which is why I've given it a 3)...

- It's not written in C
- I'd eliminate the variable found, it just complicates things needlessly
- Give the function four parameters and allow aliasing of the destination array with the first input string
- You've made it a variable number arguments function for no reason I can see!
Aescleal 3-Jun-12 15:10pm View
   
Nice to see easy to follow self documenting code.
Aescleal 3-Jun-12 14:58pm View
   
Sorry, can't comment on why it doesn't open for you, it does for me!

Have a look at the URL i've tacked on the end of the answer and see if that helps
Aescleal 1-Jun-12 16:53pm View
   
Reason for my vote of 2
For an article with the tag C you don't discuss anything much to do with C . For example there's no coverage of using RAII to overcome resource management issues, mapping cursors to iterators - in general how you'd cook up a C interface to the library.
Aescleal 1-Jun-12 16:02pm View
   
Hello person that gave me a two - could you please explain why you scored me the way you did? This isn't because I wish to go and hit all your posts by voting them down but because I want to do three things:

- Correct any factual inaccuracies
- Improve the communication and presentation of things I've said to make them more accessible
- Have a record of why people disagree with me so other people can see what the points of contention are and make up their own mind.

In all cases I want to learn, so please give me some clues about what I'm missing!
Aescleal 1-Jun-12 6:46am View
   
While I agree with a lot of the advice here (and it's a lot better than most textbooks and lecturers give out) I would add:-

- never use std::auto_ptr. If that's all you've got then grab a copy of boost
- for variable sized buffers std::vector works pretty well
- immediately assign anything that has ownership transferred to your code to either std::unique_ptr or std::shared_ptr
Aescleal 1-Jun-12 2:15am View
   
That won't close the view, that'll close the top level frame window and the entire application.
Aescleal 31-May-12 10:38am View
   
If you ever fancy changing your braces http://astyle.sourceforge.net/astyle.html is worth a look.
Aescleal 31-May-12 10:03am View
   
To be brutally honest it's really a justification for writing code the way I like :-) The same as my penchant for Allman braces - it's all taste (or lack of it, depending on who you ask) innit?
Aescleal 31-May-12 8:55am View
   
This strikes me as one of the courts of last resort when debugging memory allocation problems but a handy one to know when nothing else works.
Aescleal 31-May-12 8:06am View
   
Underscores are great - you can run variable names with underscores through a spell checker while you generally can't with camel case names.
Aescleal 31-May-12 6:07am View
   
It's a shame that the technical lead or project manager has this attitude. If you don't use newer, safer ways of programming then you're just making it harder to maintain.

Good luck, which I really hope you don't need!
Aescleal 31-May-12 3:55am View
   
It can help, you just have to give it a bit of help by telling it when to break - either by telling it where to break explicitly or when a certain data condition occurs. As it can help with other stuff the DebugBreak thing I've done a lot, even in production code. Messing up a functions parameters is a fairly fatal logic error so I throw an exception and in debug builds I DebugBreak first.
Aescleal 30-May-12 8:03am View
   
5 for the interesting reference - keep me busy for 30 minutes :-)
Aescleal 30-May-12 7:49am View
   
Friend isn't a panacea in this case. It's perfectly possible to call public member functions of A from B and vice-versa without needing to resort to friends.
Aescleal 27-May-12 2:43am View
   
Your comment's incorrect in the private section - the four functions there have been defined (i.e. got a defining declaration in standard speak) as well as declared.
Aescleal 27-May-12 2:21am View
   
To be brutally honest old son, if you're going for any job as a programmer or software engineer you ought to know how to sort a lump of data using arbitrary criteria. Even if you don't remember how to implement the various algorithms (merge sort, gnome sort, heap sort, insertion sort, etc.) at least know how to use a language's standard library. Both C and C++ have functions bundled with all standard conforming compilers that'll do what you want. In both cases it's one line plus a function/functor/lambda to do a comparison.

And say we tell you and you get through the front door of the company you're applying to and they ask you to explain "your" solution. You're really going to up sh*t creak without a paddle and the bung out.
Aescleal 27-May-12 2:09am View
   
As promised :-)
Aescleal 26-May-12 3:10am View
   
Hi Soren, make this a solution and you'll get a 5 from me! It's good advice well worthy of a decent rating.
Aescleal 25-May-12 5:18am View
   
If you mean you have to discard the last line of data in the file, then you can delay writing the values to the file and updating the totals and line counter by one line.

Ah, hang on, see what the problem is from the data file format. To get rid of the data in the columns you don't want read them into variables but don't do anything with them.
Aescleal 25-May-12 5:17am View
   
Deleted
If you mean you have to discard the last line of data in the file, then you can delay writing the values to the file and updating the totals and line counter by one line.
Aescleal 24-May-12 21:32pm View
   
Isn't it just one subtraction... Every time around the loop it's:

x = 15 - x;

The Knuth comment was just that I reckoned this was the sort of maths you'd need to solve about half the exercises in "The Art of Computer Programming."
Aescleal 24-May-12 17:28pm View
   
+5 - I like this one, just subtraction - I doubt anyone can come up with a better answer. The power of maths, worship it!

Admittedly I wouldn't have got it without the explanation. Knuth factor 5/10.
Aescleal 24-May-12 13:09pm View
   
If you want to delete an object with a private destructor write a static member function of the class and do a delete in there. As it's a member of the class you can call private functions on objects. Or if you don't want a static then have a friend function - much the same effect either way, there are arguments for both.
Aescleal 24-May-12 12:39pm View
   
Have -1 for missing that declaring new private stops heap allocation but have one back for suggesting symmetric functions for heap based only - I should have had that in my answer!
Aescleal 24-May-12 12:38pm View
   
I have no idea what he's trying to accomplish, but some C++ programming idioms like having members doing a delete this; as their last operation - modeless dialogues in MFC for example. The problem comes when what if some muppet creates an object on the stack of these types? When they go out of scope they try and delete themselves and all sort of interesting things can happen.

As for why you'd want stack based objects only I can only just think of is stopping idiot ex-Java programmers using new everywhere, but maybe that's just people I work with. :-)
Aescleal 24-May-12 12:37pm View
   
Deleted
I have no idea what he's trying to accomplish, but some C++ programming idioms like having members doing a delete this; as their last operation - modeless dialogues in MFC for example. The problem comes when what if some muppet creates an object on the stack of these types? When they go out of scope they try and delete themselves and all sort of interesting things can happen.

As for why you'd want stack based objects only I can only just think of is stopping idiot ex-Java programmers using new everywhere, but maybe that's just people I work with. :-)
Aescleal 24-May-12 12:32pm View
   
When MyClass::create() gets called there's no object created so I can't see how that works. I've given you a three so far, if you clear that up I'll bump it up.
Aescleal 24-May-12 12:22pm View
   
Shhh, no one can see my friends, apart from me
Aescleal 24-May-12 8:35am View
   
Gave this a 5 - not because there was anything too insightful about the question BUT SA's answer's well worth a read and as most people have filters set at 3.0 they wouldn't have seen it.
Aescleal 24-May-12 8:19am View
   
Looks like half the conversation's disappeared! :-)
Aescleal 24-May-12 6:42am View
   
Well you've got a friend you can start working through scenarios with. Grab him, two mugs of whatever drink you like, a way of recording stuff and get going!
Aescleal 24-May-12 6:40am View
   
hi Griff, neither the C or C++ standard say that parameters have to be evaluated in the order they're presented to the function. All they say is that all the parameters will be evaluated before they're presented.
Aescleal 24-May-12 6:36am View
   
No it's not - it's related to a concept called sequence points. These are points in the program where the observable behaviour of the program is defined and making assumptions about the order of execution between these points is undefined.
Aescleal 24-May-12 6:32am View
   
If you're not a programmer then you might be a bit out of luck actually implementing anything like this.
Aescleal 23-May-12 13:54pm View
   
That's just a detail change for the "output them to the output file".
Aescleal 22-May-12 13:47pm View
   
And that's particularly good if you're really limited with memory and someone gives you the data as a string you can sort.
Aescleal 22-May-12 13:01pm View
   
Gave this a 3 cause:

- My old bugbear, using built in arrays when a vector would work as well and be less source code - i.e. the declaration of the array and initialisation would only be one line. Thinking about it declaring and initialising the array should only be one line!

- I couldn't see what the second loop was up to then it dawned on me it was traversing an arbitrary array of characters and counting the number of each value. This was due to some pretty weird choices of variables and styles of coding (e.g. reusing i, using n=n+1 rather than n++ or ++n.
Aescleal 22-May-12 11:38am View
   
Alas the assumption was for years that a pointer and int were the same size. However this isn't the case any more - most compiler vendors have decided that there's no point in having a default 64 bit int.

Luckily I gave up casting pointers to ints ages ago.
Aescleal 21-May-12 14:37pm View
   
The problem here is the questioner doesn't want to find if an element exists (which is what binary search does) but to actually find the book that corresponds to the search parameter.

Really sorting is just a means to an end - it's the sort of thing you do once and then just run find repeatedly over your collection. If you use a presorted collection (e.g. a map) then you don't need to sort anything, although it'll still take O(nlogn) time to complete.
Aescleal 21-May-12 13:00pm View
   
And use FormatMessage to get the text representation. Ironically considering FormatMessage is one of the biggest pains in the bum in the Windows API.
Aescleal 21-May-12 7:35am View
   
Get your friend to post the question then and everything he's done so far to solve it. And if you think my comments are foolish then don't follow the advice in the second paragraph and see where it gets you.
Aescleal 19-May-12 5:50am View
   
I was going to mark you down (ugh, suggesting an explicit loop) until I saw the last sentence. That alone was worth a five!
Aescleal 19-May-12 5:48am View
   
If you want to provide more information for a question, edit the question!

Oh and implementing your own classes for things like lists just sucks. The standard library has collections, why not use them?
Aescleal 19-May-12 3:35am View
   
I only gave this a 3 'cause it's 2012, not 1994. Using atoi, character arrays and manually closing streams aren't good practices and shouldn't be encouraged. If the kids of today see this they'll think this is the way C++ is supposed to be. I'll have to put up with yet more badly informed programmers in my workplace and I've got enough of those already.
Aescleal 19-May-12 3:29am View
   
I gave the question a 5 even though the question was fairly bad in it's presentation 'cause:

- It was pretty easy to see what the questioner was on about
- Problems with extraction operators interacting with getline are pretty common and if it can be answered for one person it can be helpful for loads of people. As most people have their visibility filters set to 3.0 or less this question would become invisible and I didn't want that
Aescleal 18-May-12 10:26am View
   
They don't have to agree to not use the program - if the company as a whole don't want them using it, management have told them not to use it and they still do and the company won't sack them then concentrate on other things. Life's too short.

Or get the cash of your boss to buy a central management system - or even better move the buggers onto linux without Wine installed. Run it now you buggers.
Aescleal 18-May-12 10:19am View
   
I'd say so as well, but hey, if someone wants a job in the security industry then doing this sort of project - even if it fails miserably - would help show he knows some of the issues.
Aescleal 18-May-12 10:13am View
   
I did actually mean it - it's a bit rich coming to a site where there are professional software engineers and asking how to remove something you've copied illegally.

He didn't even have the sense to say "I've downloaded a no-CD hack for <game> 'cause I don't like a CD whirring away in the drive..."
Aescleal 18-May-12 10:08am View
   
How about:

bool is_computer_laptop( std::ostream &output_stream, std::istream &input_stream )
{
output_stream << "Please unplug your computer from the mains or UPS\n"
<< "Press any character key when you have" << std::end;

char c; input_stream >> c;

return true;
}
Aescleal 18-May-12 9:59am View
   
That was a very polite response. I think I might have just said something like "FOAD warezboy."
Aescleal 18-May-12 7:52am View
   
I've been a bit fierce and hit you with a 1 for two reasons: The website you referenced wasn't in English and there was no warning it was a foreign language site. Second you could have introduced it for the questioner - just posting a URL is a bit like chucking a book at someone and they don't know which bits are relevant to them.

Add a bit of explanation and I'll happily vote your answer up - especially if you summarise what the website is about for us poor mono-linguists.
Aescleal 18-May-12 7:49am View
   
I wouldn't recommend using SendMessage either - might be worth adding to your answer why you don't. Personally I don't like it as it can cause deadlocks but I'd be interested in hearing if you have any other reasons.
Aescleal 18-May-12 3:27am View
   
Reason for my vote of 3
Two big problems with this lot:

- Someone can crash their program with it. Use std::basic_string instead and the problem goes away. AND it makes your code far simpler.

- Don't use C functions everywhere. Everything you're doing in C you can do far easier in C

I'd also:

- stick them all in one class (ini_file, or CIniFile if you like MS's naming convention). If anything CIniFileReader/Writer are interfaces that CInitFile implements. If you do that you can reimplement your interfaces later as CRegistryKey or something to do the same thing.

- template it on the character type you want to use. Then you can use multiple types of character in the same application

Sorry to sound so harsh but I really hate code that can crash when it needn't - especially when it's code I wrote. I also think that code that looks like it was written in 1993 when it wasn't isn't doing a lot for new C programmers who might think this is the to be programming in 2012.
Aescleal 17-May-12 17:49pm View
   
If you ignore imports and relocations what you find on the disk is pretty similar to the _TEXT section of the program. The data is going to be completely different and that's where a bit of malware will be doing it's dirty deeds from.
Aescleal 15-May-12 7:04am View
   
Ask yourself the following... what happens if someone uses your class like this:

A a;

std::vector<char> path_data( 256, 'a' );
a.setPathFile( &path_data[ 0 ] );

You'll end up stomping all over memory you shouldn't and you'll probably end up crashing your program miles away from where the error happened.

So don't mess around with C style character arrays in C++ programs. Use a pair of strings the way infant_coder suggested (albeit in a pretty ill-described manner) and less people will be able to crash your code by accident or design.
Aescleal 15-May-12 5:41am View
   
Have a another 5 for uni-voter madness...
Aescleal 14-May-12 2:46am View
   
It's a variable length argument list - the compiler can't check the parameters.
Aescleal 14-May-12 2:28am View
   
It might cause any sort of program error, but not where you reckon it does. It messes up the stack so the exception will happen when something happens to:

- an automatic variable that's now in a screwed up state
- a return to an address that's not marked as a code page

I've bunged random scanf family function calls in 6 different programs and they all crashed, but none crashed at the site of the sprintf style call. Why not trace your code through with a debugger and see where it all goes wrong?

And if you want a function to screw your code up to cause an exception write code to actually cause the exception you want WHEN you want it and don't fanny about with something that'll fail some indeterminate time in the future.
Aescleal 12-May-12 3:06am View
   
I didn't use parental control software (which, as you say is generally complete rubbish) - I just didn't tell them the admin password and left them just in the users group. Funnily enough for people that seemed to install everything they haven't missed it.
Aescleal 11-May-12 9:53am View
   
I've used parental control - on the computers my parents and my in-laws use. They used to install all sorts of crap on their computers and then wonder why they went wrong.
Aescleal 10-May-12 13:45pm View
   
I've noticed that people who've never programmed in C have fewer problems with initialiser list syntax in C++ than those that have. Even with built in types you want to avoid the whole assignment thing going on it constructors just so people reading your code don't think it's a good idea with objects.

And, just for completeness, hopefully coming to a compiler near you soon, uniform initialisation syntax:

int a { 27 };

Looks ghastly but I'm sure I'll get used to it when I have something to practise with.

Cheers,

Ash
Aescleal 10-May-12 13:19pm View
   
What's the point of Google if it's not for searching for technical information, pornography or being sold things?

Which bit don't you know? How to do the SQL bit, how to call a database from C++ or Delphi or the Windows programming bit (hooking window procedures)?
Aescleal 8-May-12 10:46am View
   
Good point about different speeds of code - debug code usually moves slower than release code so it might expose a threading threading issue like reading a pointer before it's written by another thread.

Ash
Aescleal 30-Apr-12 8:26am View
   
To get the __stdcall version of main to link I used an assembler to create an ALIAS for _main@12 (in the VC++ case) to _main. That worked without mangling the run time but crashed if you accessed envp, argv was correct as it was the middle one of three arguments.

To get it working rather than crashing I modified the (actually wrote a small lump of) startup code to push the parameters in reverse order and then call _main@12 rather than mess about with an ALIAS for _main.

So as I said, it's the name mangling that stops the linker failing. Get rid of that with an ALIAS and it'll link, and probably fail horribly (because as you've pointed out, the parameters are in the right order).

There is a way of getting __stdcall main() to not only link and run but work properly with VC++ out of the box (if you've got one with an assembler in the box). The way I did it was populate a table of three thunks, each of which stacked the correct number of parameters and then called the appropriate __stdcall main (either _main@4, _main@8, _main@12). Using the order I specified object files to the linker I could make sure that the programmer written main was entered into a thunk while the other two were populated by stub functions from another object file. The final bit is working out which one to run and (this is the really disgusting bit, I'm not proud) you have all the stub functions overlaying each other - i.e. having the same address. Then you can compare a function address in the entry and call it if it's not the stub.

The scary thing was that the linker did most of the heavy lifting, it was only 20 lines of assembly (including the table definitions).

Anyway, this was the sort of trick I've learned over the years programming devices and using C in non-hosted environments. You get used to this sort of disgusting hack - and I sure as hell wouldn't advocate using it in a hosted environment.
Aescleal 29-Apr-12 18:08pm View
   
The linker fails when you specify main as __stdcall because MS compilers decorate the name of a __stdcall function with the number of bytes cleaned off the stack when the function returns. There's no reason why you couldn't have a compiler using a __stdcall style (as in parameter passing method, not name decoration). You can see this by using a binary editor to change the symbol for a stdcall main (from _main@12 to _main) or by using either GCC or Digital Mars that support aliasing through #pragmas. Your program will then link but crash when it returns from main or (probably) when you use the argv parameter.

Anyway you hit the salient points I was aiming for so have a 5!

Quick Edit: I've just knocked up two minimal startups for VC++, one expecting main as __cdecl and the other expecting main as __stdall and they both linked an worked. Slightly surprisingly as it wouldn't surprise me if the compiler had done something a bit special with main. There again I was using the C compiler which doesn't have things like implicit return 0 the way the C++ compiler does.
Aescleal 29-Apr-12 5:53am View
   
Deleted
As Albert said it looks like the compiler's choosing the wrong overload for the function. However I can't see why you need the cast in the call if you're appending an object of exactly the same type. You should be able to write:

m_string.AddTail( &t.m_string );

So go back to VC6, take the cast out and see what it says when you try and compile it. That might give you (and us) a better idea of what's going on.

Another question, what's cstring?

Incidentally having public data members is a really crap idea. It's really hard to keep your class's invariants intact if you let any old Tom, Dick or Harry fiddle with their bits. AND m_string is a really bad name as well - it's a sodding list!