Earlier quoted context omitted.
The purpose of int foo(int x[static 10]) is not to produce a warning - that's just a nice possible side-effect (and only in some cases). The real purpose is to allow the compiler to optimise the compilation of the foo() function itself, under the assumption that x will always point to the first element of an array of at least 10 elements.
At least or exactly 10 elements?
Some dark corners of C
61–70 of 175 posts
Re: Some dark corners of C
#62Someone should do "Dark corners of C++". Nevermind, it would take more than the Lord of the Rings triology.
Re: Some dark corners of C
#63Fun! Lots more ambiguities in C++. But a challenge to find them in C. My favorite: [] are just '+'
Re: Some dark corners of C
#64Earlier quoted context omitted.
It's necessarily a bad question, it makes you think about how parsers work. But for an entrance exam, it's slightly hardcore :)
To get it right you have to be able to pick it apart according to specified rules. Being able to work with formally specified rules is an integral part in the study of computer science (also, other STEM majors). I'd say it's a perfectly valid question, as long as someone points out that one should stay away as far as possible from this sort of code.
Unless you know the actual parsing rules, there's no way to know if a real parser would be greedy or not (or perhaps it might try to be clever?). This is nothing more than a trivia question, which does not test aptitude or intelligence.
Re: Some dark corners of C
#65Re: Some dark corners of C
#66I don't get it. What will happen if you violate the language semantics? They call it 'dark corners'? If you hit your head against a wall, it will hurt. Is it a 'dark corner' of life? Overall, the presentation is very weak, like from a yesterday's graduate.
Did you notice that not all of these corners violated any clause of the standard? I've got quite a bit of experience with C, and I haven't heard of the "static" array size feature before, which seems extremely useful.
Re: Some dark corners of C
#67Earlier quoted context omitted.
> which shall not be named So... not that telling then.
It's obviously JavaScript and PHP that are being referred to. Of the C "dark corners" that are problematic, it'd be extremely rare to run into them in most real-world code. You'd have to intentionally go out of your way to write code that will trigger them, and this code often looks obviously suspicious. It's very much the opposite with JavaScript and PHP. A world of pain and danger opens up the moment you do somethi…
Re: Some dark corners of C
#68Earlier quoted context omitted.
The pre-processor is independent and a macro expanded before the C compiler sees it.
The preprocessor is a part of the standardized translation process, and if the standard says that certain things are not allowed in a well-formed C program, it does not matter at which stage the compiler is.
Re: Some dark corners of C
#69Took me awhile to understand this; single quotes define single characters, and for some C decided to allow multiple character character constants but leave their value as implementation-defined. Discussion: http://zipcon.net/~swhite/docs/computers/languages/c_multi-c...
Re: Some dark corners of C
#70Is there a way to disable the fade-in? It makes scanning impossible.