Singapore's Prime Minister Shares His C++ Sudoku Solver Code 230
itwbennett writes: Several weeks ago, during a speech at the Founders Forum Smart Nation Singapore Reception, Singapore's prime minister Lee Hsien Loong said that he used to enjoy programming, and that the last program he wrote was a Sudoku solver in C++. To back that up, earlier today he announced (on Facebook and Twitter) that his code is available to download. He wrote on Facebook that he wrote the program 'several years ago' and that the code does 'a backtrack search, choosing the next cell to guess which minimises the fanout.'
It may have a .cpp extension but it's all C code (Score:2, Informative)
I guess C++ just sounds higher tech.
Re:It may have a .cpp extension but it's all C cod (Score:5, Informative)
Its also all legal C++. Just because it doesn't use the advanced features doesn't mean it isn't C++. I'd argue that for something this simple its even better code this way.
Re: (Score:2)
Technically C++ (Score:5, Insightful)
Re:Technically C++ (Score:5, Insightful)
Heh, leave it to the tech community to start nitpicking which language was actually used rather than the fact that we're seeing the very rare sight of a computer programmer in political office.
I took a look at the code - yeah, it's really just C code, but that's fine for a tiny project like this. Nice code, very clean and readable, but not very well commented.
Re: (Score:2)
Heh, leave it to the tech community to start nitpicking which language was actually used rather than the fact that we're seeing the very rare sight of a computer programmer in political office.
I took a look at the code - yeah, it's really just C code, but that's fine for a tiny project like this. Nice code, very clean and readable, but not very well commented.
Well he might be following Uncle Bob's Clean Code concepts and not filling his code with comments that could become crufty and misleading over time.
Re: (Score:2)
Heh, leave it to the tech community to start nitpicking which language was actually used rather than the fact that we're seeing the very rare sight of a computer programmer in political office.
I took a look at the code - yeah, it's really just C code, but that's fine for a tiny project like this. Nice code, very clean and readable, but not very well commented.
Well he might be following Uncle Bob's Clean Code concepts and not filling his code with comments that could become crufty and misleading over time.
I take that back after reading all the one letter variable names :)
Re: (Score:3)
The comments are definitely c++.
Re:Technically C++ (Score:5, Insightful)
Since Dice, and really well before, fuck all of that technicality. If the dude can solve sudoku in anything other than a pencil, should we really nitpick?
Re: (Score:2)
Given the date he wrote it my guess is it would not have compiled under any standard c compiler. He does most of the foward declarations, but he uses C++ style comments and C++ style void declarations. So, while it might not be OOP it is C++ and likely not valid C.
I'll grab the code tommorow and see what standards gcc4.8 will compiler it under.
Re: (Score:2)
It will. I suggest you bone up on C99.
Re: (Score:2)
Well... probably more accurate to call that C code. It's compilable under a C++ complier, but offhand I didn't spot anything that really made it C++-specific. Not a knock on the Prime Minister, but it might even be a little more geek cred to call it a Sudoku solver in C.
Extra points then to him for writing code to solve a problem, and not writing code to demonstrate his cleverness. Which is what the worst of C++ programmers usually do.
Re: (Score:2)
// comments were added to the C standard. Not good old ANSI see but still ok.
I haven't looked at the code, but the one thing I usually trip over when having to write pure C instead of C++ that's really mostly C is that everything has to be declared at the top of the function... Always. even some variable you only use in the IF $DEBUG block, I normally declare those in the if $debug block where it occurs, rather than creating a 2nd if debug block at the top of the function just to declare it.
And stuff like t
Re:Technically C++ (Score:4, Insightful)
everything has to be declared at the top of the function... Always.
That's not true, and has never been. Until about 16 years ago, you had to declare your variables at the beginning of a block/compound statement. That can be well within the function.
As of about 16 years ago, you're even allowed to freely mix your declarations and code.
[incoherent gibberish]. And stuff like that.
Yeah. The kind of stuff you seem largely unfamiliar with.
General hint: If your functions are so long that having to (suppose this was indeed the case) declare/define all your variables at the top becomes a serious annoyance, then chances are that your functions are too long/do too much. Fix that instead.
Re: (Score:2)
General hint: If your functions are so long that having to (suppose this was indeed the case) declare/define all your variables at the top becomes a serious annoyance, then chances are that your functions are too long/do too much. Fix that instead.
More general hint: The principle of minimum scope exists for a reason. Declare your variables at the point where they can be initialised, not at some arbitrary point and you make life easier for people trying to understand the lifetime of the variable.
Re: (Score:2)
I don't understand why you'd be telling me this, unless for some reason you have the same misconception about C89 that GP had - the gibberish about 'top of function'
Re: (Score:2)
Re: (Score:2)
More general hint: The principle of minimum scope exists for a reason. Declare your variables at the point where they can be initialised, not at some arbitrary point and you make life easier for people trying to understand the lifetime of the variable.
Sorry for double posting, but your more general hint is largely moot after after applying my less general hint, because there won't be as much code in a function in order to make it confusing wrt. to scope and storage duration anymore.
Re: (Score:2)
Yeah. The kind of stuff you seem largely unfamiliar with.
Lol, yes, relax. I'm not a pure C guy and I won't offend you by pretending to be.
That's not true, and has never been. Until about 16 years ago, you had to declare your variables at the beginning of a block/compound statement. That can be well within the function.
You know, until I saw it in this thread, it never occurred to me to just open a new block for the purposes of inlining a debug declaration. Thanks, I'll use that.
As of about 16 years ago, you're even allowed to freely mix your declarations and code.
Cool beans. The one C program I do have to maintain (a small 'plugin' DLL for an embedded system) I have to compile with Visual Studio 2010, which doesn't support C99 syntax. So as of about today I'm still not allowed to, even if the rest of the world has been enjoying
Re: (Score:2)
I have to compile with Visual Studio 2010, which doesn't support C99 syntax. So as of about today I'm still not allowed to, even if the rest of the world has been enjoying it for 16 years. VS2012 doesn't have it either; but i hear VS2013 does. :)
Yes and no; VS2013 seems to understand a bit more or C99, but that isn't because Microsoft would suddenly have started caring about their C compiler. Their C++ compiler got a bit of an upgrade wrt. more recent changes to the C++ standard, and the C compiler understanding a few C99 idioms is largely a side-effect/waste-product of that process.
The specific example I gave was the issue:
An IF DEBUG; where the variable was only used within the debug conditional. [...]
Okay, I see what you mean now.
Your note that I can start a block anywhere -- Thanks; until now it hadn't occurred to me to use that expressly to inline declarations for debug blocks.
My pleasure. Would you mind returning the favor and teach me how you post code in a /. comment without /. eating the indentation?
Re: (Score:2)
code tags of course. ;)
<code> </code>
And to post tags with out /. eating those html entities for less than and greater than:
< and > and & for the ampersand itself
Re: (Score:2)
Re: (Score:2)
// comments were added to the C standard. Not good old ANSI see but still ok.
Bzzt, wrong. The last ANSI approved version of C is C99, which includes // as a comment delimiter.
Re: (Score:2)
Bzzt, wrong.
I'm not sure about that.
ANSI C, also known as C89 and C90 depending on the year of ratification
https://en.wikipedia.org/wiki/... [wikipedia.org]
Yes it also says:
In March 2000, ANSI adopted the ISO/IEC 9899:1999 standard. This standard is commonly referred to as C99.
Thus C99 is an ANSI standard, but its not "ANSI C"
When you say "ANSI C" its still C89/90.
At least that's my take on it.
Re: Technically C++ (Score:5, Informative)
Put in context (Score:5, Informative)
The guy was a Senior Wrangler (top math undergrad) at Cambridge before going to governance. I would hope he'd have picked up some coding skills along the way.
Now with some other leaders, I'm impressed when they spell their names right.
Re: Put in context (Score:5, Informative)
Wiki link to those who aren't across Cambridge lingo
http://en.m.wikipedia.org/wiki/Senior_Wrangler_%28University_of_Cambridge%29
The Senior Wrangler is the top mathematics undergraduate at Cambridge University in England, a position once regarded as "the greatest intellectual achievement attainable in Britain."
Re: (Score:2, Informative)
The Senior Wrangler is the top mathematics undergraduate at Cambridge University in England, a position once regarded as "the greatest intellectual achievement attainable in Britain."
In other news wiping an adult mans arse [wikipedia.org] was once considered the greatest political achievement attainable not by birth in Britain.
Re: (Score:2)
The actual code (Score:5, Informative)
How's about including a link to the actual code?
Here you go:
https://drive.google.com/folde... [google.com]
OR:
https://github.com/Doppp/LHL-S... [github.com]
Re: (Score:2)
What I like in this prog is that he optimizes the process by simply considering that since any 1-9 digit can only be once in each column, each row, and each of the nine 3×3 sub-grids, he uses a 10 bits int and associate 2^i with a digit (instead of an array, or worse checking all digits each tim
Over use of back-tracking (Score:2)
Free Amos Yee (Score:2, Interesting)
Hey, The guy released his Sudoku solver code, and that's great!
Now how about using the same logical prowess to release Amos Yee?
https://youtu.be/dD4y3U4TfeY [youtu.be]
The PM writes good code (Score:2)
I was able to compile it with both gcc and g++, even though it seems to have been written for a Windoze system. So yes, it is legal as both C and C++ code.
No idea how to run it. Was expecting "You are standing in an open field west of a white house, with a boarded front door. There is a small mailbox here." Instead, all you get is "Row[1] :"
Re: (Score:2)
I was able to compile it with both gcc and g++ [...] [s]o yes, it is legal as both C and C++ code.
Hahaha. You're so mistaken, it's not even funny anymore. (No, not even with -ansi -pedantic). The language that gcc accepts is a twisted superset of C, so using gcc to evaluate whether it's correct C code is completely meaningless.
Re: (Score:2, Funny)
You never heard of the Obfuscated_C_Code_Contest [wikipedia.org]. Who knows what this "Sudoku Solver Code" actually does? It could be a Trojan horse to steal American freedoms.
Not that big of a deal... (Score:4, Funny)
after all our President is a "coder" too!!! :eyeroll:
Re: (Score:2)
Somebody's sense of humor went out the window.
Re: (Score:2)
I don't know.
The code resembles something you expect from a first-year programming student - there's an input buffer overflow bug waiting to happen, the array size is odd (80 byte array? why? scanf() is still called without a field length specifier, and you only use 9 of those 80 bytes in a normal case).
Perhaps it was written by him in his spare time. Or maybe it was like Obama where the base of the code was already provided and he needed to fill in a few things.
Plus the general lack of commenting, explanat
Re:Not that big of a deal... (Score:5, Insightful)
The code resembles something you expect from a first-year programming student - there's an input buffer overflow bug waiting to happen, the array size is odd (80 byte array? why? scanf() is still called without a field length specifier, and you only use 9 of those 80 bytes in a normal case).
You seem to be very optimistic in your views of first year programming students.
Here's what I see: Many years ago, I had a lovely job helping to teach people to program, and I had to review their homework. There were some whose thought processes were all over the place. There was one guy who managed to write the most convoluted code that always worked perfectly well, but I would never have hired him because reviewing it was just too painful. And there was one student who wrote code that I could scan in half a minute and see that it was correct and worked. And that's what this guy's code looks like.
"Perhaps it was written by him in his spare time". OF COURSE it was written in his spare time. His a prime minister, he doesn't write code on the job. What comments do you want? The code is simple and obvious. What data structures to explain? If you are too stupid to understand them immediately, then you shouldn't be programming. What lack of error checking? What scenario do you suggest where error checking would help?
Your last sentence is a totally unfounded, vicious attack on the intellectual honesty of the man. It's disgusting. Unless you have any evidence for it, you should apologise.
Re: (Score:2)
Easy. What does (x & -x) compute, off the top of your head?
There's so much bit-twidd
Oh yeah? (Score:2)
Well, we have an ex-Prime-Minister who paints puppies, goats, and feet sticking out of bath-tubs!
Re: (Score:2)
What does he do with the rest of the dead body, that is in the bathtub?
Re: (Score:2)
Feeds it to the goats and puppies, obviously.
Well... (Score:4, Informative)
While not utilizing any of c++'s features, it is still valid c++. I think he might call it this because he may usually program in c++, but maybe just for this one project he did it in c, and since it's still legal c++ he finds it easier to just label it as c++. I actually quite like it - could use a bit more commenting, but overall very clean and readable. Should compile with a decent c or c++compiler...
Re: (Score:2)
From his Facebook post on his Sudoku solver (Score:5, Interesting)
Nice!
Re: (Score:3, Informative)
That's common knowledge.
Bit Twiddling Hacks [stanford.edu]
Re:From his Facebook post on his Sudoku solver (Score:5, Insightful)
Not among prime ministers
Re: (Score:2)
Well, it was common knowledge.
Kids these days...
Re: (Score:2, Funny)
I have been around for a long time and no well adjusted kid has ever known what a binary integer was let alone a trick that utilizes it to determine the largest power of two that divides it.
Re: (Score:2)
That's common knowledge.
Bit Twiddling Hacks [stanford.edu]
Not, too common, apparently, since this particular hack isn't in that list. It wasn't too hard to work out what it does (find the largest power of 2 that divides x or, equivalently, find the value of the lowest bit that is set) but it didn't make the Hacks list, and I don't think that's because it's too obvious.
He didn't check online?? (Score:2)
C version, 67 lines of code ...
http://rosettacode.org/wiki/Su... [rosettacode.org]
Re: (Score:2)
Quit trolling.
Names aren't unique [wikipedia.org] even if some people like to believe in Imaginary Property.
New competition (Score:5, Funny)
There should be an international coding competition between heads of state.
Re: (Score:3, Funny)
Re: (Score:2)
... and a head of state cow milking competition...
Re: (Score:2)
At least he's doing something practical, unlike the idiot we have here in Oz.
http://www.smh.com.au/content/... [smh.com.au]
Re:New competition (Score:4, Insightful)
Would have to be Heads of Government. Lee's a Prime Minister, so he's not Head of State. Singapore's Head of State is Tony Tan.
Under Singapore's Constitution President Tan has very few powers, but he still technically outranks the PM who has powers. It's similar to the system in Britain/Canada/etc. where the Queen's Head of State,* but the Prime Minister is the one who actually does everything interesting.
And yes, this is a pet peeve of mine. I spent the week Netanyahu addressed Congress in constant nerd-rage because the entire US media kept calling him a "Head of State" when he isn't.
*Altho many Canadians argue the Queen isn't their Head of State [wikipedia.org], her representative in Canada is (the Governor-General). The fact no Court's ruled on this definitively shows how important the title "Head of State" is in a Parliamentary system. Most legal scholars seem to think that the Queen is Head of State, but there is a minority that disagrees and their Constitution is not helpful on this question. But mostly nobody cares.
Re: (Score:2)
*Altho many Canadians argue the Queen isn't their Head of State [wikipedia.org], her representative in Canada is (the Governor-General). The fact no Court's ruled on this definitively shows how important the title "Head of State" is in a Parliamentary system. Most legal scholars seem to think that the Queen is Head of State, but there is a minority that disagrees and their Constitution is not helpful on this question. But mostly nobody cares.
Given that she owns the entire country it's kind of a moot point. If they piss her off she'll just kick them out.
Re: (Score:2)
*Altho many Canadians argue the Queen isn't their Head of State [wikipedia.org], her representative in Canada is (the Governor-General). The fact no Court's ruled on this definitively shows how important the title "Head of State" is in a Parliamentary system. Most legal scholars seem to think that the Queen is Head of State, but there is a minority that disagrees and their Constitution is not helpful on this question. But mostly nobody cares.
Given that she owns the entire country it's kind of a moot point. If they piss her off she'll just kick them out.
Heh. I suspect that if she tried the outcome would not be that they would leave.
Not C++ Code Because its Understandable (Score:2, Funny)
Its not C++ code because the code is understandable. For example:
1. he does not use templates, restricting himself to solving only over the integer space. what about a sudoku puzzle of strings? basics, people, this is basic stuff.
2. he is using raw loops. what about range based bi-directional iterators using lambdas? scott meyers is going to throw a tantrum.
3. free functions without namespaces or a class even. more appropriate would have been korea::south::presidental_code::sudoku_solver.
4. better yet, abst
that guy is for real (Score:3)
He was Senior Wrangler while at Cambridge. Plus, his son is one of the most productive scala programmers in the world despite only doing it in his spare time. These guys ain't dumb.
Singapore... (Score:2)
I really, really like Singapore. They are doing pretty much everything right, including having the smartest and most educated leaders in the world, by far.
I am a bit confused by their status as non-democracy though.
Re: (Score:2)
I'd guess democracy works as long as education levels are high enough and the democracy isn't diluted.
Dictatorship seems to work as well as long as education levels are high enough and corruption is avoided.
It's a good philosophical discussion where the limit is of when dictatorships are more democratic than democracies. :)
Very C like. (Score:3)
Not a great example of modern C++.
Re: (Score:2)
Modern C++ would involve solving sudoku on compile time with template metaprogramming. All the stuff with classes, virtual functions, STL etc is so 90ties...
I'm impressed (Score:3, Insightful)
There's no shortage of people ragging on the code. "It's not C++ enough to be called C++," "there's not enough comments", "it uses C stdio.h", etc. Get over it.
This looks like the sort of program I might dash out over an afternoon (maybe two) to satisfy some intellectual curiosity. Programming as play. This isn't production code, it's fun code, written to satisfy oneself.
Is it perfect? WHO CARES! That's not important. That misses the point. If you doodle in your notepad and it brings you a smile, does anyone care it's not as good as the Mona Lisa? You sure as heck don't. And that's what this code is. A doodle. It just happens to be in simple, straightforward procedural C/C++ code.
I personally think playing with programming is important. Sure, you'll write a lot of dreck. But, you'll also learn a lot. You learn real lessons when you do write dodgy code, and the dodgy code actually bites you. You also can try new things fearlessly. After all, you're programming a toy for oneself, and you're under no deadline pressure. There's no spec you have to fulfill. You can experiment and enjoy it.
Programming as play still helps build your programming reflexes. If and when you do sit down to write professional grade software, all of that play will make the basic work of programming natural. Rather than focusing your energy on the basic details of programming, you can instead focus your energy designing maintainable code that meets the business requirements and documenting that design. Writing the code just flows naturally.
So, yeah, I'm impressed. This Sudoku solver brought a smile to my face. It's incredibly cool that the prime minister shared a code doodle with us.
Not very user friendly (Score:3)
Stupid sudoku solver? (Score:4, Insightful)
It might be a 'stupid sudoku solver', like you say, but at least, that is a program that does something, rather than the congress critters who do nothing but producing massive amount of HOT AIR
Re:Stupid sudoku solver? (Score:5, Funny)
It might be a 'stupid sudoku solver', like you say, but at least, that is a program that does something, rather than the congress critters who do nothing but producing massive amount of HOT AIR
Imagine that you are a zombie apocalypse survivor, naked and wet, in a freezing winter Alaskan night, tired to death, and you can share a tent either with this Singapore's prime minister who wants you to stay awake with him and solve stupid Sudoku puzzles or with one of those "congress critters who do nothing but producing massive amount of HOT AIR" - who would be you choice?
Re: (Score:2)
Why is the Prime Minister of Singapore in Alaska after the zombie apocalypse?
Re: (Score:2)
I guess that's just as believable as the rest of the scenario.
Re: (Score:2)
Imagine that you are a zombie apocalypse survivor
I've seen walking dead, and if that show is any guide for zombie behaviour and properties, it would seem to me that the military would have no problem taking them all out in a few days, and restore order.
Re: (Score:2)
The Germans taught that to the Greeks when they forcefully took a loan from a conquered Greece during WW2, then spent the money and refused to repay when the war was over.
Re: (Score:2)
The feeling is unlikely to be mutual.
Depends on the section of Europe. France has long been leery of Muslims, and the UK is starting to move in that direction as well.
Re: (Score:2)
Leave it to Slashdotters to denigrate our democratic representatives and idolize a glorified dictator.
I hear Putin wrestles bears, clearly hes better for a country than our congress!
Re: (Score:2)
hmmm.... solving fizzbuzz....
( code is in the R language BTW)
Re: (Score:2)
Re: (Score:2)
just come to Greece
As soon as I'm done here.. But looks like this year, finally! ('cause I feel like the guy in the middle with regards to Hellas [youtube.com]!
Re:Lead By Example?! (Score:4, Funny)
but our former prime-minister had a restaurant... our great Greek dinner with mousaka,
Which one? You'd have hoped with that experience he might have had some idea how to balance the books. Did his restaurant go broke?
Re:Lead By Example?! (Score:4, Informative)
but our former prime-minister had a restaurant... our great Greek dinner with mousaka,
Which one? You'd have hoped with that experience he might have had some idea how to balance the books. Did his restaurant go broke?
It was mister Samaras, the one who just lost the elections - (he claims) his restaurant did just fine (he had it years ago, together with a business partner, while studing in USA - yes, one more Greek restaurant in the States!). To be fair he did a good job as a prime minister in the elimination of deficit, he not only balanced the books, but provided a (significant) surplus. Our new prime minister...well...!
Re: (Score:2)
If someone can create a recursive sudoku solver, he can do other stuff. What about a brute force password cracker with shortcuts? Since a zombie apocalypse isn't coming soon, and food is easy to come by, i would actually prefer an expert coder.
Re: (Score:2)
Any zombie survival team needs an expert in at least four fields: Combat, medicine, survival and technology.
Combat and medicine keep the team alive.
Survival collects food, at least for the first few months - after that it becomes safer to return to the urban areas where you can just grab canned food with ease.
Technology establishes communications with other survivors and maintains the radio gear and power source.
Re: (Score:2)
He forgot to capitalize the H in Hell, but than was correct in usage. Mandarin compared to C/C++ is not temporal which is what then is used for.
Re: (Score:3, Informative)
void Succeed()
That's actually more C++'ish, a C programmer would put it as
void Succeed(void)
Which means in C what the former means in C++.
</nitpick>
Apart from that, yeah. It's pretty much C. Almost C89, even, were it not for the C++ style comments and two instances of mixed declarations and code.
Re: (Score:2, Funny)
a C programmer would put it as void Succeed(void)
A C programmer would put it as 'void succeed()' or even 'succeed()'.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
GP doesn't seem to understand the difference between no parameters and unspecified parameters...
In C, the compiler doesn't care if you return nothing from a 'int' function. So, while 'void f()' would be cleaner, only 'f()' without a return type set (ie 'int') is seen a lot.
:-)
Re: (Score:2)
In C, the compiler
"The" compiler? You do realize that C is a language specification, right?
doesn't care if you return nothing from a 'int' function.
That's just wrong. It's possible (though unlikely) that your compiler "doesn't care"> It's undefined behaviour to fail to return a value from a non-void function. It doesn't get much wronger; and as a consequence of UB, the compiler isn't even required to do anything meaninful afterwards. If your particular implementation tolerates it, fine, but please don't conclude that it must be how C works then. You're outside the scope of C at
Asserting implementation-defined behavior (Score:2)
You're not making it better by actively promoting horrible, non-portable, implementation-dependent and error-prone coding practices.
What's wrong with making assumptions about implementation-defined behaviors and using static assertions to verify them? For example, would it be poor form to assume (and assert) things like 8-bit bytes or that the character set is ASCII, and if so, why?
This way, the compiler will fail and kick out a diagnostic if the e
Re: (Score:2)
You're not making it better by actively promoting horrible, non-portable, implementation-dependent and error-prone coding practices.
What's wrong with [depending on] implementation-defined behaviors and using static assertions to verify them?
(Ignoring that that's quite a stretch from what I said, and deliberately ignoring the 'error-prone' part), if you do verify your assumptions about the implementations then of course it's less horrible. However, you do pay the price in losing portability, so if it isn't for a particular good reason, not unnecessarily relying on implementation-defined or unspecified behaviour is preferrable.
For example, would it be poor form to assume (and assert) things like 8-bit bytes or that the character set is ASCII, and if so, why?
This way, the compiler will fail and kick out a diagnostic if the environment doesn't match the assumptions.
That's quite a hack (but better than nothing, sure). If you had a hard requirement such as "has to be ASCII-based" or
Accessing the data being deserialized (Score:2)
If you had a hard requirement such as "has to be ASCII-based" or "char must be 8 bits wide", then I'd wonder where it comes from.
The fact that Internet protocols use 8-bit bytes and either ASCII or its superset UTF-8.
For requiring char to be of some specific width, there's hardly a reason, unless you're improperly (de)serializing.
Last time I checked, the C standard offered no facility for networking, graphics, or even enumeration of the files in a directory. This means most nontrivial interactive programs will need to use POSIX or Windows functions, which are defined in the POSIX and Win32 specifications but are undefined behavior from the perspective of the C standard, in order to access the data that the program is (de)serializing in the first
Re: (Score:2)
There is legal and portable C that is not C++. Yes, C++ is close to a superset, but it is NOT a superset.
Re: (Score:3)
Also compiles under gcc and g++. Except for the file extension;)
You cannot use "$compiler compiles it" to determine whether it's portable or correct C, just look at all the non-C garbage gcc happily accepts.
Though in this case i'm not saying it wouldn't be correct; I just pointed out that C programmers usually wouldn't declare their function to have an unspecified number of arguments when what they really want is no arguments. It's not wrong; just unusual, C++ influenced style.
the PM's code is legal and portable C
Possibles &= ~(Possibles & -Possibles);
Portable my ass. This at least requires two's
Re: (Score:2)
for (size_t i = 0; i puts("poof");
Duh, /. ate a <. That should read:
for (size_t i = 0; i < sizeof '0'; i++) puts("poof");
Re: (Score:2)
Besides, the real failure about that line is that in C++ it should probably read #include <cstdio> (unless i'm mistaken; i do know my C, but C++ not so much)