News for hackers. Stuff that matters.
Re:Computer Science Interview Questions with C++ Solutions by NAFV_P on Sunday December 22, 2013 @07:08AM (#6950103)
>Implement a simple linked list in C (not C++). It can be compiled on a C++ compiler, but do not use any feature of C++.

Er, which standard of C?

Re:Computer Science Interview Questions with C++ Solutions by kps on Sunday December 22, 2013 @02:29PM (#6951351)
You get the job if you can think of a non-trivial way in which in matters.
Re:Computer Science Interview Questions with C++ Solutions by Danieru on Sunday December 22, 2013 @03:03PM (#6951492)
That's pretty easy. Pre-C89 did not have void pointers, thus a generic linked list would have to use char pointers.

Beyond the wrong-ness of using an incorrect dereferencer type you would also force any users of your linked list to make an explicit cast. Meanwhile a post-C89 linked list could return void *. Thus taking advantage of C's implicit cast of void pointers.

Meanwhile if you compiled this second void pointer returning linked list under a C++ compiler would have to make an explicit cast just like in the pre-C89 case.

Re:Computer Science Interview Questions with C++ Solutions by NAFV_P on Sunday December 22, 2013 @06:06PM (#6952187)
Sorry I should have explained myself better:

I am referring to the C-standards, and I don't consider K&R to be one of them. I tried compiling the source with:

  gcc file -std=c89 -Wall -o out
&&

  gcc file -std=c99 -Wall -o out
I get a score of errors thrown at me.

Not one of them mentioned a void* or char, they don't appear in the code. The float which holds the data is located within the struct itself.

The first nine errors were all practically identical:

  error: unknown type name 'LL_Element'
I don't know much c99, but when it comes to c89 whenever an instance of a struct some_type* is declared the keyword struct also has to precede the type: ie. struct some_type some_instance;. The only way I am aware of that overcomes this is the use of typedef in the original declaration.

I'll have to check whether it is mentioned in the 1988 edition of The C programming language or another text, but if I recall correctly the term tag is used to refer to struct declarations.

Also the original code had the headers <cstdlib> && <cstdio>. I think these headers have all their functions declared as inline, a non-existent keyword with regards to c89. I had to change the headers to the traditional .h style header in order to have a chance of getting the code to fit through the slot, so to speak.

I don't have a CS degree, I teach myself, so if I have missed something or made a faux pas, please say so.

Re:Computer Science Interview Questions with C++ Solutions by kps on Sunday December 22, 2013 @04:06PM (#6951734)
K&R (V7) cc happily handles implicit casts of char* ; void* is just char* with a new name and a pair of handcuffs. If you're writing a linked list, though, you'd be using a 'struct listnode *next' in any dialect.