| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 01:55
•
by
Kuba
(unregistered)
|
Nope. At the last loop the p will be equal to a. Methinks. The problem is that incrementing a pointer one past the end of the allocated memory area is an undefined operation per standard (IIRC). a+N-1 does not need to be optimized, it may literally take address of the array, increment it by N elements, and then move back one element. On most platforms this will work as you expect it to. But it's not guaranteed to. As for filling the array in C, there's no standard way IIRC. If sizeof(char)==sizeof(short) then memset will work. In C++, there's std::fill. I don't think there are real scenarios where the code would b0rk, unless you're on some crazy architecture. Maybe some big iron would mind such code. I mean architectures contorted enough to have a dereferenceable (w/o violations) NULL pointers. I can't think of a commonplace "consumer" architecture where pointer arithmetic isn't done modulo some power of two, and pointers can't store crap without further ado. I'd have to look up how Turbo C did pointer arithmetic, but in all models I think this would still work as you expect, even if the segment registers would be tweaked along the way. Am I missing something obvious (it's late here)? |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 02:35
•
by
tsmith
(unregistered)
|
That's pretty harsh. Did she not understand the concept of a namespace? What about polymorphism, operator overloading, virtual functions, is-a versus has-a, or other object-oriented concepts? Or did you end the interview before you could find out? Tool. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 04:14
•
by
Filthy_Liar
(unregistered)
|
Nope. In order for loop to break the comparison p >= amust evaluate to false. Thus p must have decremented to a pointer value before the array.
The concern of a+N-1 does not actually apply to this case. The calculation will be correct even if a[] takes up the last N addressable words (which is why the spec makes *(a+N) undefined to begin with). The problem with the original code was --p. After the last loop, when p == &a[0], there is no gaurantee that --p will result in a p value less than &a[0]. Specifically if &a[0] = 0 (a[0] is the first addressable word), then the last --p will result in p much larger than a since pointers are unsigned.
I don't think that matters, memset(a,42,sizeof(short)*N);should always work.
If &a[0] < sizeof(short *) then the pointer arithmetic on p will underflow causing p to have a very large value. I'm not sure which OS would give you a data segment with a virtual address starting at 0x00000, but it is conceivable and it would die.
I wouldn't call it obvious. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 04:25
•
by
Filthy_Liar
(unregistered)
|
Contrary to what was stated, their standards are not "immensely high", they are "exclusive." They may be high as well, but the primary effect is exclusivity. There is a difference. Most employers make this mistake. They will pass over extraordinarily capable candidates because "they didn't have enough knowledge of Specific Technology X." I'm sure most employers would turn down Donald Knuth for a job writing Ruby code because he didn't have specific knowledge of Ruby even though he is one of the most renowned computer scientists in the world. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 05:29
•
by
AdT
(unregistered)
|
Because the pass-by-value parameter is constructed by the calling function, saving one copy operation in some cases. For instance:
This will create an empty string, fill the string using the stream operator >>, pass a reference to this string on to twistAndPrint, where it will be copied. On the other hand, if twistAndPrint accepted an std::string, the compiler could easily figure out that since "input" is no longer used after "twistAndPrint" (the only method that will be called on "input" after twistAndPrint is the destructor), the compiler could create "input" on the stack in a location suitable to the subsequent invocation of twistAndPrint, and no copy operation would be necessary. Of course, given sufficient knowledge of what twistAndPrint does and where it is used, the compiler might make the same optimization in the "const std::string&" case. But the point is that this requires the compiler to perform global optimization, using much more knowledge of the entire program, whereas the original optimization requires only local ("peephole") knowledge including the already known signature of twistAndPrint. Therefore, real world compilers will be much more likely to perform the optimization in the pass-by-value case than in the pass-by-reference case. Also, there could be incompatible uses of twistAndPrint which prevent the optimization in the latter case anyhow (most importantly if twistAndPrint is used in a way which prevents the compiler from altering the calling convention without breaking the linked program, i.e. exported to external programs or passed to external programs as a callback). For further information, see "Move Constructors" by Andrei Alexandrescu. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 05:42
•
by
AdT
(unregistered)
|
No, that part is ok. It is fine to point one past the end of an array, as long as you don't dereference, and this is what users of the STL do all the time (remember that pointers are iterators!). The problem is that this code tries to move the pointer one past the beginning of the array, and that is illegal.
Yes, segmented memory. The array could be at offset 0 in a memory segment. The corresponding pointer is not a NULL pointer, but either the decrement itself or the following comparison will easily cause mayhem. Segmented memory may be an oddity on x86 (32 or 64 bit) today because the flat memory model basically won, but no exotic processor architecture is necessary, only a more or less exotic rsp. outdated OS.
In real mode, the compiler-generated code may be smart enough to handle this case. But even then, in Borland C++ it would not work in all memory models because only in the "huge" memory model would the compiler bother to insert expensive segment adjustment code for pointer arithmetic in all cases. In other memory models, you had to use a special type of far pointer if you wanted that to happen IIRC. In protected mode, segment adjustment isn't even possible in the general case, so all bets are off. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 05:49
•
by
AdT
(unregistered)
|
And she has an penchant for using the wrong indefinite article. On the other hand, she does have a pleasant phony voice. :-)
Oh, right, I almost forgot that MS invented the STL, and SGI (IRIX anyone?) never implemented that sucker, and never donated the code to the GNU libc++ project, and that libc++ is actually not available on a huge range of UNIX platforms be they Solaris, Linux, Mac OS X or many others. Sheesh. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 06:43
•
by
eryn
(unregistered)
|
i've lost count the number of times this topic has come up for discussion. wrt the = sign in vb, it's context sensitive. hmmm... what's that on ur face? oh it's just egg. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 07:12
•
by
John
(unregistered)
|
|
I'm (almost) certain that the interviewed guy said that as a joke (no code reuse, just likes to start over).
|
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 07:21
•
by
Jim
(unregistered)
|
As A C novice, I keep wondering why ++i is used instead of i++. Wouldn't that overflow the array at the last iteration, and keep the short with index 0 uninitialized?? |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 07:30
•
by
dpm
|
Of course it works. You end up with every element of the array set to 10794, but no errors occur, which I assume is your definition of the word "work". memset() assigns a value to every byte in the referenced memory, and your "sizeof short" *looks* like a clue but it's not. The function receives the address of the array, a value, and the number of bytes to fill, period . . . so instead of 002A002A002A002A002A002A the memory will look like 2A2A2A2A2A2A2A2A2A2A2A2A |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 07:51
•
by
Khanmots
(unregistered)
|
for(expr_1; expr_2; expr_3) is equivilent to expr_1; The ++i or i++ is evaluated entirely in expr_3, it doesn't change *when* expr_3 itself is evaluated. The difference between ++i and i++ is what value it evaluates to... which in the case of the for loop the value the expression evaluates to is never used. Here's an example with behavior analogous to the for loop... notice how the choice of i++ or ++i doesn't matter... j matches i. int i = 0; Here's an example of when it would matter. int i = 0; And here's another example where it matters. int i[N]; Hope this helps! |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 08:14
•
by
snoofle
|
Answer: My greatest weakness is that I have little patience for incompetence... If I have to explain something more than 3-4 times to someone, I tend to insist that they make more of an effort. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 08:45
•
by
UpNDown
|
Not much difference in C, the difference is in C++. The "++object" form is more efficient when dealing with real objects. Using "object++" instead would require that a copy of the object be made before incrementing the real one. The copy is then returned instead of the original. With "++object" a reference to the real one can be returned. Not important when you're dealing with ints, or where the value is not being used, but just a good practice to get into, especially with poorly written code that includes dynamic allocations in the object (which you don't want to have to check for). I believe there is a section in Effective C++ about this. The rule is: if you have pointers in your object, you need a destructor, an assignment constructor and a copy constructor (once again, if I remember right). This is also an area where different compilers may produce different behaviour -- one may produce a copy of the object, another may not. It's done behind the scenes for you, or *against* you when things go awry. You want to avoid that difference in programs you want to be portable. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 09:03
•
by
usitas
(unregistered)
|
Fixed that for ya. I used gVIM all the time, even in windows. VIM has had syntax highlighting for years... |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 09:29
•
by
I walked the dinosaur
(unregistered)
|
By "junior developers", I assume you mean high-school students? Seriously though, when I first looked at teh codez above, I didn't see the missing "=" either. Of course I know the difference, but "trick" questions like that are retarded. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 09:32
•
by
noName
(unregistered)
|
|
In this case ++i is the only op being done so its irrelevant.
However dont do "a[++i] = 42;". "a[i++] = 42;" would be OK though... :D Search google for «C unary prefix posfix». First hit will get you: "The increment/decrement operators can be applied before (prefix) or after (postfix) the operand. The code result++; and ++result; will both end in result being incremented by one. The only difference is that the prefix version (++result) evaluates to the incremented value, whereas the postfix version (result++) evaluates to the original value. If you are just performing a simple increment/decrement, it doesn't really matter which version you choose. But if you use this operator in part of a larger expression, the one that you choose may make a significant difference." |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 09:36
•
by
noName
(unregistered)
|
|
If you test candidates for
x=3; if (x=0) cout<<"0"; else cout<<"not 0"; *and* ask for a verbose explanation of the result than you may start getting some pretty explanations: "0 is diferent of 3; therefore «not 0»!" |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 09:48
•
by
Anon Fred
(unregistered)
|
|
I must say I love these esoteric discussions of the C spec. Every time I think I know the language someone knocks me down a peg.
But it's how I learn. Thanks guys. |
|
K.D. you did not make me laugh. Why don't you just accept that the brilliant guy has never got a project wrong? As surprising as it may be, skilled and smart developers can get things always almost right (or fixed them on the go) and not let a project failed by incompetence.
I, for one, admire his honesty. He probably knew that what he was going to say could hurt him. I think *he* tested *you*. Something like "Let's if my (potential) boss can cope with a guy like me". |
"Always almost right". 2+2 = 3.99999, but consistently so.
And he ended up saying something dumb that hurt him. Zero points awarded.
I wouldn't want someone on my team who had to be "coped with". Why can't you play well with others? |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 11:16
•
by
Edward Royce
(unregistered)
|
I'd rather use UltraEdit frankly. Not a huge fan of vi. Or of emacs. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 11:19
•
by
Edward Royce
(unregistered)
|
Hmmmm. Counting coup, nerd-style. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 11:34
•
by
An oppressed mass
(unregistered)
|
|
That's why an experienced programmer will always write.
if ( 5==x ) { } We had this arguement on here before: "An expert programmer shouldn't rely on the compiler to find his mistakes" vs "An expert programmer uses all the help he can get" |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 12:09
•
by
K.D.
(unregistered)
|
|
(I'm the original poster/interviewer in the story)
Yes, that in fact, I believe, was what he meant. He didn't believe in ever going back to refer to previous work (of his or anyone else's) but rather wanted to start every single project with a clean slate. Admirable in a sense, but why on earth would you want to re-invent simple common elements over and over? And to the person who said that asking someone to point out their weaknesses is a flawed interview style -- well, actually, it's worked very well for me. This candidate was horrible flawed, and by opening a door, he pointed it out himself. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 12:14
•
by
CB
(unregistered)
|
Heh, the job I am about to leave gave the latter as an answer when I asked. Actually, they volunteered it as if it were a source of pride. Gah. Bonus points if said in-house "source control" is written in VB6. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 14:30
•
by
Justin
(unregistered)
|
|
I was about to say the same thing. To the best of my knowledge, most university classes do not discuss namespaces. I feel like many C++ programmers just know that they need to put using namespace std; at the top of their files.
Additionally, I have to wonder how important it is that a job candidate understand namespaces on the day that they start if they show overall competence. First, namespaces are easy to understand, so, it wouldn't take long to explain to explain if your organization really is making use of them. Second, I think that maybe half of all organizations actually take care to use them in any meaningful way. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 15:35
•
by
Pecos Bill
|
At least there's one valid reason. Because you could tell them that they failed and if they ask why, you could say you don't have time to teach them. If you did tell them, you aren't opening up a legal battle if you are right. The HIGH cost of legal battles will keep most from even attempting. People have been graded since early childhood and are going to accept it (if mentally sound and if not then you might have a valid reason.) If you ARE rejecting based on personal attributes, "not a good fit" is used a lot or you could cop out but that wasn't WhiskeyJack's point. Great argument for status quo lovers. I hope people that pick #3 get LOTS of annoying calls asking. |
Re: K.D. you're wrong!
2008-05-08 16:07
•
by
chaoticsynergy
(unregistered)
|
Honestly I'm shocked at the number of pple that posted stuff similar to this. Nobody has ever put out 100% perfect work. If you can't accept your own faults, then you'll never improve. Yes your projects may all have been completed successfully ... that doesn't mean there weren't decisions you made that you had to go back and change, or in hind-sight wished you could have changed. I hope I get asked that question at future interviews. Then at least I'll know that I'll be working with people that grow ... instead of stagnate in the knowledge that everything they produce is perfect. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 16:56
•
by
Anonymous Coward
(unregistered)
|
Yes, I agree. This is the perfect kind of question I want my company to be asking in an interview. Why worry about actual coding ability when they can rattle off obscure facts about the C language specification that are rarely applicable to modern architectures? After all, as we all know, everyone who is worth their salt has been coding in C since the days of segmented memory. Furthermore, I think it goes without saying that people who enjoy picking apart trick questions are the very kind of people I want designing my algorithms. Sure, its one thing if the algorithm *works*, but is it *optimized*? No doubt we would all agree that all algorithms we write should exhibit the same kind of cleverness as these questions. Cleverness = maintainability. To extend this idea a bit, I think I will ask interview questions about real-mode programming and maybe pepper in a few questions about the ALGOL specification. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-08 18:27
•
by
real_aardvark
|
OK, that was just very silly. And very funny. Thanks. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-09 00:04
•
by
Procedural
(unregistered)
|
|
I was in Jonestown, Tanzania once and saw a strip mall shop sign announcing Kinko-like services and more. The shop was also offering typing services. The name, written in bold letters in front of the shop, was "Helen's Secretalrial Services". I didln't enquire about their serlvices. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-09 15:25
•
by
Manic Mailman
(unregistered)
|
I actually agree with you that posing trick questions about obscure trivia is not a great interview technique, but it can be a good learning technique. If you're not interested in understanding or learning why something like underflow on pointer arithmetic might result in undefined behavior, then you might want to stay away from C/C++ because those languages love to stick you with runtime bugs that result in rare instances of that undefined behavior biting you in the ass. Without a doubt, this is a major drawback of C/C++; other languages let you largely stop worring about such details. So, while maybe being able to pick out the obscure potential bug is not something to look for in a potential hire, I'd certainly like anyone who I'm working with on a C/C++ project to at least *want* to understand or learn about these pitfalls if someone's pointing them out. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-11 02:58
•
by
C++ dev
(unregistered)
|
|
Yes, I agree. It makes me wonder if the author understands the language very well himself. There certainly are cases where a mutable value parameter is preferable.
At companies in the Seattle where I have interviewed - and worked - at (Amazon, Microsoft, Real) there is much more of an emphasis placed on higher level design than on basic language semantics. When I have interviewed for our team I always focus on finding out what the candidate can do well and how they would be able to contribute. Often intellectual horsepower is a better measure of a candidate than language specifics anyway. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-12 11:21
•
by
Random832
|
There is a difference between not knowing what a standard library is, and not knowing what its namespace is, or that it has one, since some implementations let you call the entire standard library (or what parts of it are implemented) without it. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-12 11:30
•
by
Random832
|
The policy "Can't tell them why they're not hired for legal reasons" has always translated in my mind to "Some of our reasons for not hiring people are illegal". |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-12 11:42
•
by
Random832
|
This is never true on a normal programming environment (it may be true for some exotic embedded systems) - the reason: sizeof(char) always == 1. sizeof(short) is ALMOST NEVER going to be that, because a short has to be at least 16 bits, and a char is _normally_ eight bits. |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-12 13:08
•
by
real_aardvark
|
I'm sorry, I wasn't really paying attention. What did you say your greatest weakness was, again? |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-15 07:20
•
by
felix
(unregistered)
|
|
Fresh out of uni my CV was short on content so I decided to employ a "professional" CV writer to rewrite it for me using all the tricks of the trade. I filled in her questionnaire and sent off the results, a couple of weeks later I received the finished article. There were _numerous_ typos including the following:
"Accurate and eloquent in witten communications." |
Re: Let's All Reinvent the Wheel... Again, and More
2008-05-16 08:37
•
by
Anonymous Coward
(unregistered)
|
Anyay? |
Re: Let's All Reinvent the Wheel... Again, and More
2008-06-28 08:33
•
by
IByte
(unregistered)
|
It's what you get when you're screwed, and you certainly are... |
Re: Let's All Reinvent the Wheel... Again, and More
2008-09-22 19:29
•
by
caught ya
(unregistered)
|
|
This is obviously engineered (poorly).
|
Re: Let's All Reinvent the Wheel... Again, and More
2008-11-10 07:26
•
by
111
(unregistered)
|
Re: Let's All Reinvent the Wheel... Again, and More
2009-01-21 23:50
•
by
sfsad
(unregistered)
|
Re: Let's All Reinvent the Wheel... Again, and More
2009-07-06 05:25
•
by
wm
(unregistered)
|
Re: Let's All Reinvent the Wheel... Again, and More
2010-03-06 23:22
•
by
Baloney Bear
(unregistered)
|
|
Oh, please, who can remember what all those acronyms mean? The question is, does she know how to -use- std? (What does it mean, anyway? Standard? And whenever I see stdio and want to pronounce it as "studio"... Talk about poor naming conventions...)
|
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |