- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Admin
As others have pointed out: rubbish. And every single C++ compiler I know of (including VS2005) will point out that this is rubbish. Unless you are particularly rigorous in switching all manner of warnings off, in which case, pat yourselves on the back -- you have a Process! To quote from the first thing that comes up on Google when you query "c++ standard main:"
"The ISO C++ Standard (ISO/IEC 14882:1998) specifically requires main to return int. But the ISO C Standard (ISO/IEC 9899:1999) actually does not."
And the idea of invisibly casting "void" into "0" is not even worthy of contempt.
Well, there are shell scripts and there are C/C++ programs (if we're going to talk about a rather restricted universe of the "Unix Way"). Like so much about Unix, this is fucked-up and utterly retarded. "0" means success in Unix (conventionally) and failure in C/C++ (conventionally). Somewhere along the line between Martin Richards, the beloved progenitor of BCPL, and Ken Ritchie and mates, the concept of failure as 0xFFFF... (choose word size) and 0 (who cares?) got too confusing for people who have something better to do. It may have something to do with the instruction set on the PDP-8; it may have something to do with electro-magnetic characteristics of core memory, for all I know, but the end result is a bit messy. The only reason that C/C++ programs and shell scripts "agree" on the "semantics" of success/failure is that vastly more idiots write shell scripts than write C/C++ programs. It's Gresham's Law in computer terms.
Arguments about semantics here are bogus. There is one way to succeed: you succeed. There is one way to fail: you fail. (With a passing nod to FILE_NOT_FOUND.) Anything else is a side-effect, kiddies. Jeez. I'm being drawn more and more to functional languages, every day.
But, to the WTF. It isn't one. Regardless of mis-spellings, stupid use of manifest constants and the pre-processor rather than const variables, idiotic dependence upon what is declared before what else, etc: we are told that the solution works.
That would make it preferable to around 60% upwards of "Made in America" or "Made in the EU" solutions.
Quit yer bitchin'.
Admin
You forgot one.
#define class struct
Admin
Well, there are no guarantees that
will work at all. But if you really, really, want to act like a prat, then anders is correct: you very definitely want to redefine classes as structs. Why? Well, think when the public/private keyword is first required.
This is all very well if you're just trying to access member functions (or, I suppose, data) of an individual class (or, I suppose, now a struct). It's a little trickier with inheritance. Chances are, you'll end up with a class that can be used polymorphically where it shouldn't be, or has virtual methods calling some random pimpl acquired silently through a Koenig look-up, or ... the mind boggles.
Look, if C++ is too difficult for you, go back to Java. That's what the language was designed for, for God's sake.
(It's also very popular with outsourcing companies, or so I've heard.)
Admin
Absolutely nothing wrong with that - until the minute someone decides to make these helpful:
which results in
and
to mean two very different things.
Admin
Since no one else has said it, I will:
TRWTF is in the comments
Admin
Just the title of this WTF brings back memories. I set up a database backup system which tracked the status of backups of a large number of remote sites, and replicated the data to a central location. About a year later we set up a website to track the statuses. After we set up the website, someone noticed I had misspelled successful as "sucessful". By then, of course, there was a lot of data everywhere with the wrong spelling, so we still have code to correct my misspelling, several years later.
Admin
Apart from "SUCSESS", my only worry with the macros in the article would be knowing which ones are used where.
Admin
As I often have to test my own code (how can anybody believe a programmer could test is own stuff) I often do The Monkey Test: just slap on your keyboard like a maniac and see what happens. That is more or less the way your future user will be acting.
KEBOARD_NOT_FOUND = True ????
Admin
You are right. I have also had the experience of something like this in a lecacy system, they had multiple categories in code but because they might be seen as the same value when they were different categories they were named "ACCESSORIES","ACESSORIES" and "ACCESORIES". Then a filter on the presentation to write the friendly name.
Very painful...
CAPTCHA is a very on message "praesent"
Admin
"SUCCESS is misspelled"
That can actually be a good thing. I remember finding a few "SUCCESS" #defines in include files under /usr/include, which pretty much ruined any chance of using that as a constant in a class, value in an enum or anything like that. I wish more people would misspell their #defines, as they cause me too much trouble when they are spelled correctly. :)
Admin
"Oh, and as for my attempts at showing the boss how bad our outsourced code is? !SUCSESS. After all, the application did work." So, true?
Admin
You do know that it doesn't really make much of a difference unless you fail to specify public/private/protected? A struct is a class in C++, only struct defaults to public members and class to private members.
Admin
Genitus: ah, yes. Copulus/Labia spawn. Famed Roman warrior.
That's assuming warrior is pronounced as two syllables...
Admin
Not exactly:
<g7umah> /home/g7umah $ 0 && 0 && 0 ksh: 0: not found
Were you kidding? I couldn't tell.
Admin
But...
Admin
Nobody every said that Ancient Greek poetry, or indeed drumming, was easy.
Addendum (2008-02-14 18:34): Well, it's a little late, but what I actually meant was (that being two dactyls, right there) iambic pentameters; not dactylic.
Ho hum.
Admin
Ouch!
Admin
Why is the first thing I thought of upon seeing this post "CONGRATURATION! YOU SUCSESS!"?
Admin
#define FAILED FAILURE
Admin
PDP family processors had bit-mapped jump conditions, leading to the convention that 1 = True. Processors which jump on the sign bit lead to the convention that -1 = true.
1's complement arithmetic leads to the convention that 1 = true, 2's complement arithmetic leads to the convention that -1 = true.
There is an inherent contradiction between the belief that C is 'close to the machine' and the belief that C is portable.
This matches the other inherent contradiction between the belief that Unix is 'natural' and the belief that Unix is portable.
Admin
Admin
What's worse is that
return "SUCCESS";
puts the string "SUCCESS" on the stack, the function then returns and the stack variable is freed, so the function ends up returning a pointer to invalid memory!
Admin
"Yes," Jake adds, "it returns a literal char*, which is then cast to an STL string on the function return, which is then cast to a c_str in the comparison, which is finally compared with strstr(). All this for a Boolean! "
Fail.
the pointer to the literal string is used to create a std::string object on which c_str() function is then called. There's no casting involved.
Sounds like "Jake's" C++ competence leaves something to desire as well!
Admin
What a worthless load of half-truths and misquotations. First, in STL parlance, there aren't collections but containers. Second, only the vector<bool> specialization is affected by the misdesign from good intentions (and it ends up being neither a vector nor a container in the strict sense). Third, this has nothing at all to do with bool itself.
Admin
Might be an old oe, but... #define true false; #define false true; //now try and debug this, suckers
Admin
I will sometimes use those definitions in unit tests to allow unit tests to view or pre-set internal states that are just too hard to get to initially with a test harness...so those defines are not totally out of place.. if used in the correct context.
Admin
"...which is then cast to an STL string on the function return, which is then cast to a c_str..."
... uh... actually nothing is being cast to anything here. A std::string is being instantiated with a const char* (aka, string literal) and then a const char* is being returned from a std::string (e.g., const char* std::string.c_str()). Utterly ridiculous, really, but the other WTF here is that the submitter clearly doesn't grasp the difference between type casting and object instantiation / value returns.