Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pesch
Nov 4, 2006
Wholly Chao
You aren't going to corrupt your I/O buffer using C++'s interface to your I/O buffer. That would just be silly.

That being said, the easiest way to solve your problem would be to get the entire line of input from the user via cin.getline() and then deal with it once you have the entire thing.

Try looking at the stringstream class as a place to store the user's input. It may help you.

http://www.cplusplus.com/reference/iostream/stringstream/

Adbot
ADBOT LOVES YOU

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->

Pesch posted:

You aren't going to corrupt your I/O buffer using C++'s interface to your I/O buffer. That would just be silly.

That being said, the easiest way to solve your problem would be to get the entire line of input from the user via cin.getline() and then deal with it once you have the entire thing.

Try looking at the stringstream class as a place to store the user's input. It may help you.

http://www.cplusplus.com/reference/iostream/stringstream/

Hmm, what's the difference between "getline(cin, var, delim)", and "cin.getline(var, delim)"?

Edit: Also, reading up on the istream classes, it looks like these are mostly meant for extraction of a character array (basic string). Is there a way to use these, or something else I can use, to extract a string array?

Cosmopolitan fucked around with this message at 04:55 on Nov 24, 2008

Smackbilly
Jan 3, 2001
What kind of a name is Pizza Organ! anyway?

Anunnaki posted:

I'm sure if I knew what you were talking about, I wouldn't be here asking for help. :confused:

If cin >> str will get one letter's worth of morse code, and you need to get multiple letters worth of morse code, and loops make things repeat, why not use a loop that repeatedly gets one letter's worth of morse code until you have all the letters? It really doesn't need to be any more complicated than that.

User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!
So, you can associate more than one thing to a unique key? In the example, mapping numbers of days to months, means you can have "31 days" associated with all the months that have 31 days?

Edit - Assuming that's true, can you read a maps keys sequentially?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

User0015 posted:

So, you can associate more than one thing to a unique key? In the example, mapping numbers of days to months, means you can have "31 days" associated with all the months that have 31 days?

What are you talking about

User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!

Avenging Dentist posted:

What are you talking about

http://www.cppreference.com/wiki/stl/map/start

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->

Smackbilly posted:

If cin >> str will get one letter's worth of morse code, and you need to get multiple letters worth of morse code, and loops make things repeat, why not use a loop that repeatedly gets one letter's worth of morse code until you have all the letters? It really doesn't need to be any more complicated than that.

Because a series of cins, going one character by one, is exactly what I'm trying to avoid. Although I'm running out of steam with this, so I think I might just have to fall back on that anyway.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

No. You are talking about a multimap, not a map. I don't know why you're talking about it, but nevertheless, you are.

Anunnaki posted:

Because a series of cins, going one character by one, is exactly what I'm trying to avoid. Although I'm running out of steam with this, so I think I might just have to fall back on that anyway.

Why would you intentionally try to make it more difficult for yourself to tokenize the input??? If you're worried about trailing whitespace loving things up just do the same thing to a stringstream after copying from getline.

Avenging Dentist fucked around with this message at 05:11 on Nov 24, 2008

hexadecimal
Nov 23, 2008

by Fragmaster

User0015 posted:

So, you can associate more than one thing to a unique key? In the example, mapping numbers of days to months, means you can have "31 days" associated with all the months that have 31 days?

Edit - Assuming that's true, can you read a maps keys sequentially?

to associate more than one thing to a key you need multimaps. with normal maps you just have one mapping per each key.

you can read map's key sequentially. if you use map<T,E>::iterator then such iterator returns reference to a pair<T,E> where T is key and E is entry. also all entries in map are sorted based on key values. You can provide custom comparator function to order differently.

vvvvvvv you should be able to just like i described with map, but I am not sure what exactly it uses for each entry, as I never used them. perhaps its just again pair<T,E> where keys are just repeated? I am not sure.

hexadecimal fucked around with this message at 05:11 on Nov 24, 2008

User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!

Avenging Dentist posted:

No. You are talking about a multimap, not a map. I don't know why you're talking about it, but nevertheless, you are.

That's surprisingly helpful.

Can you sequentially read a multimap?

^^^^^^^

Thank you!

hexadecimal
Nov 23, 2008

by Fragmaster

User0015 posted:

That's surprisingly helpful.

Can you sequentially read a multimap?

^^^^^^^

Thank you!

check out this #define I have found somewhere and have been using for a while. It makes iterating through STL containers a lot easier.

code:
#define FOREACH(_it,_l) for(__typeof((_l).begin()) _it=((_l).begin());(_it)!=(_l).end();(_it)++) 

map<string,int> some_map;
....
down the road
....

FOREACH( entry, some_map )
{
    entry->second++; // remember that iterator is essentially a pointer. 
                     // and first and second methods on pair return first and second elements 
                     // in pair respectively.  by doing this i increase every value in the map by 1.
}

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

hexadecimal posted:

check out this #define I have found somewhere and have been using for a while. It makes iterating through STL containers a lot easier.

Stop writing awful #defines, jesus christ. Boost.Foreach has already soundly trounced that attempt anyway, and C++0x will have range-for rendering all of this moot.

hexadecimal
Nov 23, 2008

by Fragmaster

Avenging Dentist posted:

Stop writing awful #defines, jesus christ. Boost.Foreach has already soundly trounced that attempt anyway, and C++0x will have range-for rendering all of this moot.

well what if you don't want to use boost, or can't? its not an awful #define its very useful, at least for me :)

floWenoL
Oct 23, 2002

hexadecimal posted:

well what if you don't want to use boost, or can't? its not an awful #define its very useful, at least for me :)

See what happens when either _it or _l is a computed expression (e.g., FOREACH(i++, my_map)).

It's a pretty awful macro.

User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!
Your #define is beyond me. That's ok though. I had an idea and it turns out multimaps might be helpful.

hexadecimal
Nov 23, 2008

by Fragmaster

floWenoL posted:

See what happens when either _it or _l is a computed expression (e.g., FOREACH(i++, my_map)).

It's a pretty awful macro.

why would you ever want to do that? and what is a better macro to take care of that case?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

hexadecimal posted:

well what if you don't want to use boost, or can't? its not an awful #define its very useful, at least for me :)

If you don't want to use Boost, you're probably an idiot. The only reason you'd be banned from using Boost is if your school/job has specific coding standards precluding it, and they're probably not going to like you polluting the preprocessor namespace with a bunch of extra symbols that can cause spurious substitutions.

Besides that, your #define obscures compiler errors, behaves differently from the C++0x range-for standard, and uses post-increment on the iterator. :barf:

Oh, also it relies on a nonstandard compiler intrinsic (__typeof) with no appropriate fallback for compilers that don't support it (such as MSVC, which you may know as the primary compiler for Windows). There's a reason that people use Boost and not their own homegrown hacks when attempting to hack in language features.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Avenging Dentist posted:

If you don't want to use Boost, you're probably an idiot.

He calls people "duder", so I think there's no "probably" about it.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
I got bored so I made a solution in plain C (possibly with some GNUisms). In C++, instead of using the read line+strtok approach, you'd either read a line then split it using something like stringSplit, or you'd just read exactly one token at a time from the input. You might also use a map or a vector or something instead of a big array for the table of Morse codes, but whatever.

Now I kind of want to try to golf the decoding problem.

Edit: fixed the constants table, because checking my work the first time would be the pansy way to program

ShoulderDaemon fucked around with this message at 06:16 on Nov 24, 2008

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Real men use Boost.Spirit and write an EBNF grammar to parse the morse code. :smug:

hexadecimal
Nov 23, 2008

by Fragmaster

Avenging Dentist posted:

Real men use Boost.Spirit and write an EBNF grammar to parse the morse code. :smug:

wow, it sounds really cool. Is it a lot better to use than lex/yacc?


vvvvvv so template meta programing is hacking templates in C++ to generate some C++ code at compile-time that makes it faster than equivalent code that does more work at run-time? It sounds pretty cool, but from what little reading i have done in past 10 minutes, the only advantage over macros seems to be that you can do recursion using this? Can you point me to any good sources to read for this? So far I have just been reading the reference on the Boost.spirit page.

hexadecimal fucked around with this message at 06:13 on Nov 24, 2008

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

hexadecimal posted:

wow, it sounds really cool. Is it a lot better to use than lex/yacc?

Axiom 1: Template metaprogramming is loving awesome.
Axiom 2: Regular programming is "ok"
Corollary 1: Let X = {x | x is a program}, Y = {y | y is a template metaprogram}, Z = X-Y.
Then ∀y∈Y,∀z∈Z (y>z)

Signs point to yes.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Avenging Dentist posted:

Real men use Boost.Spirit and write an EBNF grammar to parse the morse code. :smug:

Using a tool to build your state table seems like cheating.

code:
#include <assert.h>
#include <stdio.h>

#define START 'K'
#define FIRST '('

static struct {
	char dot, dah;
} table[] =
	{ {0,  ')'},{0,  0  },{0,  0  },{0,  '.'},{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{'\'',0 },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  '-'},{0,  0  }
	, {':',0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{'B','2'},{'?','_'},{'+',0  },{'"',0  },{'@',0  },{';','!'},{0,  '('}
	, {0,  ','},{'8',0  },{'9','0'},{'e','t'},{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{'r','w'},{'6','='},{0,  'F'},{'b','x'},{'i','a'},{0,  0  },{'z','q'}
	, {'5','4'},{'s','u'},{0,  '1'},{'c','y'},{0,  'D'},{'g','o'},{'d','k'},{'I','J'}
	, {0,  'E'},{0,  0  },{'l','C'},{'h','v'},{'n','m'},{'f','A'},{0,  '3'},{'p','j'}
	, {'/',0  },{'G',0  },{'7','H'},{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  } };

#define D(c)  (table[(int)(c - FIRST)])
#define DO(c) (D(c).dot)
#define DA(c) (D(c).dah)

#define ERR '#'

void decode(const char *str) {
	char at = START;
	while(*str){
		if (*str == '.') at = DO(at);
		else if (*str == '-') at = DA(at);
		else {
			if (at != START) putchar(at);
			at = START;
		};
		++str;
		if (at == 0) {
			putchar(ERR);
			while (*str && (*str == '.' || *str == '-')) ++str;
			at = START;
		};
	};
	if (at != START) putchar(at);
	putchar('\n');
}

int main(int argc, char *argv[]) {
	assert(argc==2);
	decode(argv[1]);
	return 0;
}
Breaks badly if you don't pass it valid Morse code because there is no error checking whatsoever. Edit: Got bored, added the 5 lines of error checking so it doesn't crash on invalid input.

ShoulderDaemon fucked around with this message at 04:29 on Feb 18, 2009

POKEMAN SAM
Jul 8, 2004

ShoulderDaemon posted:

Using a tool to build your state table seems like cheating.

This is why I love the CoC.

rasactive
Dec 25, 2007
o hai

ShoulderDaemon posted:

code:
static struct {
	char dot, dah;
} table[] =
	{ {0,  ')'},{0,  0  },{0,  0  },{0,  '.'},{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{'\[b][/b]'',0 },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  '-'},{0,  0  }
	, {':',0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{'B','2'},{'?','_'},{'+',0  },{'"',0  },{'@',0  },{';','!'},{0,  '('}
	, {0,  ','},{'8',0  },{'9','0'},{'e','t'},{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  }
	, {0,  0  },{'r','w'},{'6','='},{0,  'F'},{'b','x'},{'i','a'},{0,  0  },{'z','q'}
	, {'5','4'},{'s','u'},{0,  '1'},{'c','y'},{0,  'D'},{'g','o'},{'d','k'},{'I','J'}
	, {0,  'E'},{0,  0  },{'l','C'},{'h','v'},{'n','m'},{'f','A'},{0,  '3'},{'p','j'}
	, {'/',0  },{'G',0  },{'7','H'},{0,  0  },{0,  0  },{0,  0  },{0,  0  },{0,  0  } };

#define D(c)  (table[(int)(c - FIRST)])
#define DO(c) (D(c).dot)
#define DA(c) (D(c).dah)

I'm not sure but I think I hate you.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

ShoulderDaemon posted:

Using a tool to build your state table seems like cheating.

Yeah, but you still used a tool to build your state table.


That tool... is you. :pwn:

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Realtalkin', I wish I knew how to build parse tables manually. Maybe one of these days I should get a book on lexing/parsing.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Avenging Dentist posted:

Realtalkin', I wish I knew how to build parse tables manually. Maybe one of these days I should get a book on lexing/parsing.

After looking the poo poo that yacc and lex spit out I don't relish the idea.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

MEAT TREAT posted:

After looking the poo poo that yacc and lex spit out I don't relish the idea.

Tools tend to push out some of the worst looking state machines; it's possible to build readable state machines that aren't any slower without too much trouble. I'm not a good example of that, but I've heard about it happening from a somewhat reliable source who was probably not joking at the time.

Seriously, though, most of why mine looks terrible is because of the stupid gimmick I'm using where the index of a state maps directly to the character that should be printed if you terminate in that state. This neither saves memory nor speeds up execution, but I think it's kind of funny because it makes it almost impossible to read unless you have an ASCII table handy.

Anyway, Morse code doesn't really lend itself to a compact representation, which is sort of unfortunate because any state table is going to end up with icky holes in it. It actually gets slightly nicer if you add the latin character encodings and other extensions to the code, because they fill in some of the holes, but I didn't want to deal with those characters in C. Also, they would have made my stupid gimmick require a bunch of rows of nothing but {0 ,0 } which just looks bad. I suppose I could have filled most of those elements with random garbage because they'd never be reached, or I could store a huffman-encoded version of the table and decode it at runtime, but I'm not currently that bored.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

Avenging Dentist posted:

If you don't want to use Boost, you're probably an idiot.

This is extremely naive fyi and I'm not certain if you're a professional programmer why you can't imagine situations in which certain libraries and language features aren't available, but you're making yourself look like either a pompous moron or a troll. C++ was designed to be a multiparadigm language, and part of the reason that it's still so widely used is that it supports many features in many different ways, and there's often no One True Solution to a particular problem.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I hate to break it to you, but a good dozen libraries from Boost are in TR1 and many more are a part of TR2, so unless you're seriously arguing against the use of the standard library, you're just being stupid.

More to the point though, dismissing Boost as a whole is profoundly retarded because Boost is not a single unit. There's a world of difference between disallowing Boost.Spirit and Boost.Smart_Pointer.

Even more to the point, hexadecimal's code in this thread has been consistently awful and he needed to be taken to task for it.

Still more to the point, has there ever once been a time that I've posted something not partially intended as a flame?

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Avenging Dentist posted:

Still more to the point, has there ever once been a time that I've posted something not partially intended as a flame?
I dunno, you seemed to do it less frequently up until a couple of weeks ago.

hexadecimal
Nov 23, 2008

by Fragmaster
i made my own DFA (about 15 states) table one time for an acm problem, if that counts. It involved a lot of coffee and scratch paper.

actual C++ question: Do C++ compilers optimize tail recursive functions into iterative ones?

hexadecimal fucked around with this message at 14:53 on Nov 24, 2008

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

hexadecimal posted:

actual C++ question: Do C++ compilers optimize tail recursive functions into iterative ones?

gcc enables -foptimize-sibling-calls at -O2 and higher; I don't know about VC++. Last time I heard, gcc's TCO is unnecessarily conservative: GCC basically doesn't do the sort of analysis which lets you selectively enable the optimization, so all sorts of code can just automatically disable it. It's not the sort of thing you want to rely on unless you do.

rjmccall fucked around with this message at 15:28 on Nov 24, 2008

fartmanteau
Mar 15, 2007

Avenging Dentist posted:

Realtalkin', I wish I knew how to build parse tables manually. Maybe one of these days I should get a book on lexing/parsing.

I suggest some reading on the lemon parser. Quite educational.

Srebrenica Surprise
Aug 23, 2008

"L-O-V-E's just another word I never learned to pronounce."
This is a bit of a stupid newbie question - I haven't done C++ for a year and a half and even then I was basically at a casual level. I was also then doing it on a *nix system and now I'm being thrown into working with the console.

I'm trying to declare a two-dimensional array of pointers. I have a "Map" class, which holds a Tile **tileptr, and obviously a "Tile" class. What I want is for each element in the array to be a pointer to a separate Tile - I'm aware that it's not really the tic-tac-toe board analogy people give and 2-d arrays are just fancy memory management, but representing it this way makes it a lot easier for this particular purpose.

Since I'm dumb with pointer syntax now, I've done the following:

code:
void Map::initTiles(){
  tileptr = new Tile*[xsize];
  for (int i=0; i < ysize; i++)
   tileptr[i] = new Tile[ysize];
}
(xsize and ysize are members of the class).

However, when I execute this, the program automatically terminates. I've previously told it to draw a 25x25 grid as well and with this function commented out in the Map constructor it works perfectly, but when included I get nothing. I've tried running it in the command prompt, no go. Is this because I haven't bothered writing a destructor yet and deallocated all those Tiles, or is there something else to blame?

hexadecimal
Nov 23, 2008

by Fragmaster

Srebrenica Surprise posted:

This is a bit of a stupid newbie question - I haven't done C++ for a year and a half and even then I was basically at a casual level. I was also then doing it on a *nix system and now I'm being thrown into working with the console.

I'm trying to declare a two-dimensional array of pointers. I have a "Map" class, which holds a Tile **tileptr, and obviously a "Tile" class. What I want is for each element in the array to be a pointer to a separate Tile - I'm aware that it's not really the tic-tac-toe board analogy people give and 2-d arrays are just fancy memory management, but representing it this way makes it a lot easier for this particular purpose.

Since I'm dumb with pointer syntax now, I've done the following:

code:
void Map::initTiles(){
  tileptr = new Tile*[xsize];
  for (int i=0; i < ysize; i++)
   tileptr[i] = new Tile[ysize];
}
(xsize and ysize are members of the class).

However, when I execute this, the program automatically terminates. I've previously told it to draw a 25x25 grid as well and with this function commented out in the Map constructor it works perfectly, but when included I get nothing. I've tried running it in the command prompt, no go. Is this because I haven't bothered writing a destructor yet and deallocated all those Tiles, or is there something else to blame?

you have segmentation fault there, because xsize and ysize are not equal. tileptr is of size xsize, but in your loop you go from 0 to ysize, so if y size is bigger than xsize you definitely get seg fault.
in your loop do i < xsize instead of ysize.

also in your 2d array each element is not pointer to Tile. Use *** for that.
or you can use 2d vector. like vector<vector<Tile*> >( ysize, vector<Tile*>(xsize,NULL ) );

(USER WAS PUT ON PROBATION FOR THIS POST)

ehnus
Apr 16, 2003

Now you're thinking with portals!

hexadecimal posted:

actual C++ question: Do C++ compilers optimize tail recursive functions into iterative ones?


Some do, under certain circumstances, but I don't think anything is guaranteed. I've seen Visual C++ optimize tail recursion into a loop (/O1 and above). It sounds like GCC does it, from rjmccall's post, and I'd assume that Codewarrior does not mostly because it doesn't seem to optimize anything at all.

User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!
If anyone was up for it, I had some questions I'd like to ask via e-mail. That, or start my own thread. I don't think a thread really warrants my questions, since they'd mostly be single question/comment types.

Adbot
ADBOT LOVES YOU

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
EDIT: I am doing something wrong here, carry on

I just got some weird results trying to do a really simple benchmark of qsort versus std::sort. I use the following code:

code:
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <algorithm>

extern "C"
{

int compare_desc( const void* v1, const void* v2 )
{
	const int* i1 = reinterpret_cast < const int* >( v1 );
	const int* i2 = reinterpret_cast < const int* >( v2 );
	return *i2 - *i1;
}

}

int main( void )
{
	int arr[ 10000 ];
	std::srand( 50 );
	clock_t t = clock();
	for ( int i = 0; i < 1000; ++i )
	{
		for ( int j = 0; j < 10000; ++j ) arr[ j ] = std::rand();
		qsort( arr, 10000, sizeof( int ), &compare_desc );
	}
	clock_t e = clock();
	std::cout << ( e - t ) << "\n";
	std::srand( 50 );
	t = clock();
	for ( int i = 0; i < 1000; ++i )
	{
		for ( int j = 0; j < 10000; ++j ) arr[ j ] = std::rand();
		std::sort( arr, arr + 10000, std::greater< int >() );
	}
	e = clock();
	std::cout << ( e - t ) << "\n";
}
Using MinGW (-O3), the qsort part goes much (about three times) faster than the std::sort part, which is completely unintuitive. Ok, I thought, it might be doing some weird special processing for qsort, let's move the compare_desc function to a different file. Doing this made the qsort version go about two times slower, so obviously some special processing is going on. In Visual C++ express, the qsort version goes at about the same speed as in MinGW, but the std::sort version is about 1.5 times slower.
Does anyone know what's going on with std::sort? Is it just that GCC 3.4.4 and visual c++ express suck at optimizing, or am I doing something wrong here?

Painless fucked around with this message at 22:29 on Nov 24, 2008

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply