Actually, that's just GCC being stupidly compatible with stupid programs. MSVC ought to fail to compile this.
Printable View
It (MSVC) doesn't. It spits out two warnings, but it compiles nevertheless.
More stupid compilers. :(
I know that it's not valid C without a cast.
And with warnings enabled [or if you use gcc, -Werror] it will complain.
The fact that beginners don't enable warnings, or ignore warnings is for them to learn from - and usually it's VERY obvious when you got it wrong anyways.
Yes, C++ offers more strict type checking, but all decent compilers allow you to get warnings in C when you do that thing [even Turbo C supports a large number of warnings in this area].
If you ignore the warnings, then that's not the fault of language, is it? The language[1] has enough information in place to check types if the code is correctly written, and the compiler is able to tell if it's not got a prototype for a function. If so, it will give a warning.
[1] Assuming we are talking ANSI C, rather than original K&R C.
--
Mats
Just want to throw an FYI out there....
If you want to test a snippet of code using a *very* standards compliant compiler, then check out Comeau's online compiler here: http://www.comeaucomputing.com/tryitout/
gg
Hehe, nice analogy.
>If they're trying to sell their compiler, they should hire a good
>web designer to make the site look a little more professional.
When your product is as high quality as Comeau, you don't need to "make the sale" with pretty pictures and layouts. Rather, they should make it more convenient to buy the damn thing. :P
This is particularly true if the source code has "lived" for a long time, and portions [quite possibly CRITICAL or major functionality portions] haven't been changed for many, many years - if the code still works, then there's probably no reason for anyone to go through and update it, just because some compiler throws a few warnings.
As hobbyists, we often think of "old code" as easily replacable, but if the code is working, has been tested by you, your QA-team, your customers, and is known to be bug-free and work as the customers want it to work, then there is no good reason for a manager to approve a project of 6 months to rewrite the code to compile without warnings in the latest compiler, with no other benefit - and a risk that the changes actually break something. Have you never rewritten a function just a little bit, and found that for most parts, it works exactly like before, but you missed some subtle part that makes the new function fail or behave differently in some very special case? "If it ain't broke, don't attempt to fix it!"
The company I work for have sold the software to go into many millions of devices. If you change anything, you risk producing a bug - and if that's a "rare" bug, you may end up with a recall of our customers product from their customers, with a HUGE expense of all their customers updating the software. So we only really change things that one of our customers ask us to change!
--
Mats
There's no "technically" in here. Newbies don't define a language. The standard defines the language. Warnings are there for a reason, because many C compilers allow you to do all kinds of things against the language standard in order to allow people to cut corners and write programs to utilize non-portable features. Is it smart? I don't think so. I don't like it. I don't think it's a good thing to do. Nevertheless, I know I've seen code in industry that looks like garbage in the sense that it mixes C and C++. Does it "work for them"? Yes. Is it legal? No.
Oh really? Let's try void main() in C++ with MinGW:
Guess I can't define main() to anything.Code:: error: `main' must return `int'
: error: return type for `main' changed to `int'
It does NOT allow passing wrong arguments. The C standard is the C standard. If you violate the C standard and say it's valid C because your compiler allows you to do it, you're an idiot. You're even worse than just being just plain dumb if you ignore the warnings that tell you something is wrong. Just because your compiler allows something ridiculously stupid does not mean it's valid C.
What you appear to be displaying is a "works-for-me" type of mentality which is just begging to run into undefined behavior, regardless of whether you use C or C++.
So C++ is a superior language simply because Stroustrup turned up the warning level in the compiler like any good C programmer would? It's something I would do should I ever write a C compiler, tbh. Compliance mode first and foremost by default.
Only in your imagination. C doesn't do this.
And your lack of surprise at such an event is demonstrative of your blind dislike of C out of your hard-held belief that C++ is the language. You are welcome to any opinion, naturally, and frankly, I'm not so sure I would even want to sway you to the C side. What I would like is for you to stop the needless and ridiculous C bashing, especially for baseless and rather absurd allegations of the sort that you have either directly and indirectly charged in this topic. Kindly refrain from discussing imagined features of C and C++ as a way to further your cause. ;)
Don't take this the wrong way [usual way of starting a sentence that will sound somewhat offensive :)], but you do seem to occassionally get into this sort of arguing - whether it's on purpose or not, and whether you enjoy it or not. I chalked that down to "not old and wise enough" Now, I can't use that exceuse, _I_ probably SHOULD know better! ;)
--
Mats