Code: Select all
genSANMoveString(currentMove, moveString);
printf("%s", moveString);
Moderator: Ras
Code: Select all
genSANMoveString(currentMove, moveString);
printf("%s", moveString);
Solution 1:Bo Persson wrote:That's funny!
However, should you ever want to display something other than a double, how do you do that with printf?
As long as we only need some ints or a double, add them up, and display the result, C works just fine.Code: Select all
// In C++ Chess::Move CurrentMove; std::cout << CurrentMove; /* or in C */ printf("what goes here", &CurrentMove);
andretaff wrote:Just for the pleasure of pumping gas into our little flame war, I show you the words of Linus Torvalds:Bo Persson wrote:It teaches the use of the C++ standard library, containers, iterators, overloads, generic functions, and user defined classes, before going into the really difficult stuff like pointers and arrays.
...
There is a lot of C that is of very little use, once you have learned the better ways of C++. So start there!
http://thread.gmane.org/gmane.comp.vers ... ocus=57918C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C.
Man, this guy is insane. He's great.
(Linus doesn't like operator overloading, too much abstraction, boost, stl)
Boost would be useful, if it were part of the standard, or a de facto standard in the sense that you could rely on it to be installed everywhere. One of the main points of using C or C++, at least for me, is to make it as easy as possible for anyone, regardless of the platform, to compile and run the program. It should be possible to just unpack the source code and type 'make', without having to download any extra libraries.Gian-Carlo Pascutto wrote:Boost, which was linked above, is also good to learn. It should be considered an essential part of C++ programming nowadays.
A problem with this solution is that it is not clear how to implement the move_string() function, because of the lack of a real string type in C. You would probably have to do something like this:Zach Wegner wrote:Solution 1:
printf("%s", move_string(move));
Code: Select all
char *move_string(Move m) {
static char str[MAX_MOVE_STRING_SIZE];
sprintf(str, ...);
return str;
}
This would force you to reimplement the entire functionality of printf(), which is a lot of work, besides being ugly. Moreover, you have no type safety. There is no way to check at compile-time that the parameter paired to the %M directive in the argument list is a move.Solution 2:
custom_print("%M", move);
The more interesting Boost libraries are becoming part of the standard TR1/TR2, and recent gcc's ship them out of the box.Tord Romstad wrote: Boost would be useful, if it were part of the standard, or a de facto standard in the sense that you could rely on it to be installed everywhere.
In this case you can't really rely on very much besides the standard library, which doesn't offer portable way to deal with the things you mention (threads, sockets). In fact, that's also the main part of Boost I use exactly because of this reason. I'd rather deal with the Boost dependency that rewrite this code several times, and have to do some magic to correctly guess which version (POSIX, Win32, ...) I have to use at compile time.One of the main points of using C or C++, at least for me, is to make it as easy as possible for anyone, regardless of the platform, to compile and run the program. It should be possible to just unpack the source code and type 'make', without having to download any extra libraries.
Boost, unfortunately, is far from ubiquitous. It's not part of a standard Mac OS X install, for instance. I'd love to use it (at least for threads and sockets), but as long as it prevents my program from compiling right out of the box on some of the major operating systems, I can't.
Tord
Actually Haskell isn't pure functional. It also has stuff inside that allow imperative programming, which is why Haskell was so popular within the functional language domain.Tord Romstad wrote:Many people think so, but I don't agree, and I think most people who make such claims have never been exposed to any languages apart from descendants of Algol (like C, Pascal, Java, C#, etc.). Once you move to other paradigms, you'll quickly be forced to think about algorithms and data structures in new and initially completely alien ways. Try a concatenative language like Forth or Factor, a lazy, purely functional language like Haskell, a dynamic object-oriented language like Smalltalk, or a logic language like Prolog.mcostalba wrote:Programming languages are different, but the underlying logic is the same for all of them.
I find that learning new programming languages is an fun, addictive and often mind-bending experience, as long as the new languages are sufficiently different from those I already know (going from Pascal to C, for instance, wouldn't be a big change).
Tord
With Mac OS/X, a bunch of the system interface topics like threads and timers are already covered by NextStep, er... I meant "Cocoa". So there's not much motivation for Apple to finance Boost integration and deployment.Gian-Carlo Pascutto wrote:I was actually a bit surprised that on many Linux distributions, it's difficult to get the latest Boost without installing it yourself. The problem seems to be a combination of C++'s lack of ABI guarantees and stability. I guess Mac OS X has the same issue.