Live data from Hacker News

Some dark corners of C

docs.google.com

61–70 of 175 posts

Re: Some dark corners of C

#61
post #52
post #43

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?

At least

Re: Some dark corners of C

#63

Fun! Lots more ambiguities in C++. But a challenge to find them in C. My favorite: [] are just '+'

[] really is very well known trick question. Wwll it was on my university before they switched to other language. I think they don't event learn C there. Shame.

Re: Some dark corners of C

#64
post #54
post #46

Earlier 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.

The question assumes that you KNOW the rule, which is highly unlikely unless you've either been bitten by it or have read through the spec enough times to catch it.

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

#66
post #53
post #27

I 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.

No comma operator on the slides. Whata pitty :-)

Re: Some dark corners of C

#67
post #4

Earlier 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…

Agreed. Everytime i get back to C it's like coming back home. But first you must study it hard to make it your home. On the other hand javascript (lang i'm using at current job) is like living 'Groundhog Day' with everyday finishing with suicide. Well, not saying javascript is bad language, there are some really great things about it, but it's designed with a loaded gun put on your head all the time :-) I'd also put C++ on list of dangerous languages, because it is trying to fix C problem while introducing OOP (and in newsest standard lambdas and others), so now you have huge base for new and exciting set of ways to kill yourself. It's not even funny that simple languages like lua are getting more users everyday.

Re: Some dark corners of C

#68
post #49

Earlier 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.

I'd be glad if you can pinpoint the location in the C standard where this constraint is given.

Re: Some dark corners of C

#69
int x = 'FOO!';

Took 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...

Post reply on HN