- Had an interview
- Posted by Boudewijn Dijkstra on April 28th, 2008
Op Sat, 26 Apr 2008 15:12:57 +0200 schreef DaveN <DaveN@DaveN.COM>:
Obviously this will give inaccurate results when a+b > INT_MAX.
--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/
- Posted by Boudewijn Dijkstra on April 28th, 2008
Op Sat, 26 Apr 2008 17:09:11 +0200 schreef Chris H <chris@phaedsys.org>:
Not irrelevant at all. uC's that have 64 bytes of RAM, often have just
one register.
--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/
- Posted by Jon on April 28th, 2008
On Sat, 26 Apr 2008 02:50:37 -0700 (PDT), Kenneth Bull
<kenneth.bull@gmail.com> wrote:
It takes a nerd to ask that at an interview.
- Posted by Chris H on April 28th, 2008
In message <l5eb149pr83hl49m8cfj7r7cjkcfds09ut@4ax.com>, Jon <a@b.c>
writes
Maybe. I might ask a question like that to see the reaction of the
interviewee.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
- Posted by ArarghMail804NOSPAM@NOT.AT.Arargh.com on April 28th, 2008
On Mon, 28 Apr 2008 13:46:33 +0200, Jon <a@b.c> wrote:
I went on an interview once and they didn't ask that. But, that was
before C became common. About 1974.
However, I did get asked how many ways there were to clear a register
to zero on a IBM 360. There are quite a few. :-)
--
ArarghMail804 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html
To reply by email, remove the extra stuff from the reply address.
- Posted by Mel on April 28th, 2008
DaveN wrote:
You can trim that a bit:
a = a + b;
b = a - b;
a = a - b;
Paralleling the original using ^ as add/subtract without carry/borrow.
Using genuine add and subtract means we count on C to ignore overflow.
Mel.
- Posted by John McCabe on April 28th, 2008
On Sun, 27 Apr 2008 12:47:31 +0100, "tims next home"
<tims_new_home@yahoo.co.uk> wrote:
The temp variable option is more than likely quicker in most cases,
but speed isn't the point for the XOR trick - it's allocation of
storage.
AIUI, in nearly all cases at that sort of level of code your compiler
probably wouldn't bother using a location in RAM for the temporary
variable (probably use a register or something) so it's, as someone
else said, a bit of a pointless function.
FWIW - I've used that on interviewees, but the other way round; I
showed them the function and asked them what it does. The number of
interviewees I've had who didn't even know ^ was XOR, or didn't know
what XOR did is actually quite high (but then it wasn't me who read
the CVs and chose who to interview!).
John
- Posted by John McCabe on April 28th, 2008
On Sat, 26 Apr 2008 02:50:37 -0700 (PDT), Kenneth Bull
<kenneth.bull@gmail.com> wrote:
That sounds familiar, was it in the UK?
- Posted by Andrew Smallshaw on April 28th, 2008
On 2008-04-28, Chris H <chris@phaedsys.org> wrote:
I think I've mentioned on this group previously an associate who
begins each interview with "Are you any good?" for much the same
reasons.
The three XORs to swap trick is exactly that: a trick. Knowing it
or not knowing it is neither here nor there, particularly as there
are concerns about using it in terms of legibility, its performance
on pipelined processors, etc.
However, I could see an argument that having encountered it somewhere,
especially in a discussion such as this, is an indication of a
stronger candidate. It isn't the kind of thing that you see in
books and if it is mentioned at all at university then it is probably
only in passing as an aside. It is something that you either
encounter in the wild (which is not how I suspect most here first
heard of it) or via general discussions with others in the field,
maybe in person, maybe online.
In the first case, sure you got lucky and tripped over it somewhere.
Hearing about it in discussion, OTOH shows that you _have_had_
those kinds of discussion, not just about this but presumably on
a wide range of other issues. Those discussions presumably not
only cover this but a wide range of other 'trivia', opinions,
experiences etc that the candidate can draw on as and when required.
It also suggests you can communicate meaningfully with your peers
and have an interest in the field that goes beyond the bare essentials
needed to do your current job.
I'm not suggesting for a moment that someone is going to hire a
particular candidate because they may have read a few articles on
usenet, but exposure to the opinions, ideas, and experiences of
others is something that is potentially valuable. After all, you
are limited in how much you can accomplish first hand. If you are
familiar with the problems that have been faced by others, that
gives you a much greater (although indirect) experience base to
work with.
--
Andrew Smallshaw
andrews@sdf.lonestar.org
- Posted by Chris H on April 28th, 2008
In message <slrng1bplp.gk7.andrews@sdf.lonestar.org>, Andrew Smallshaw
<andrews@sdf.lonestar.org> writes
I had that sort of question. The answer was "compared to what/who?"
I couldn't agree more.
Exactly. It comes down to approach to problem solving and experience.
When asked some of these questions I would ask why they are being asked.
Do you really want to know if I know that trick or do I need to know the
reason for the question. IE The question is the symptom not the cause.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
- Posted by Mark Borgerson on April 28th, 2008
In article <l5eb149pr83hl49m8cfj7r7cjkcfds09ut@4ax.com>, a@b.c says...
Push A
Push B
Pop A
Pop B
;-)
I did try the XOR algorithm and found a potential problem:
short a = 4;
short b = 5;
volatile short c = 6;
volatile short d = 7;
void test(void){
a = a ^ b;
b = a ^ b;
a = a ^ b;
c = c ^ d;
d = c ^ d;
c = c ^ d;
}
With a cross-compiler for the MSP430 this gave results of 1 and 0
for a and b, but the correct results of 7 and 6 for c and d.
Apparently, an undesired optimization occurred where the compiler
simply moved the result of the first calculation into b. The code
generated was:
XOR b,a ; used absolute addresses for and b
MOV a,b ; a and b are now both 1
XOR b,b ; here's our zero result!
XOR b,a ; 0 XOR 1 = 1
For c and d, the compiler used a register as a temporary variable
and got the desired result.
Borland C++ builder got the proper result without the volatile
specifier.
Mark Borgerson
- Posted by Alex Colvin on April 28th, 2008
Note that the first version (^) is the same as the second (+-) in GF(2),
assuming your C wraps on overflow.
--
mac the naïf
- Posted by Rocky on April 28th, 2008
On Apr 28, 6:13*pm, Mark Borgerson <mborger...@comcast.net> wrote:
Rocky
- Posted by Andrey Tarasevich on April 28th, 2008
Mark Borgerson wrote:
Glitches like that usually occur when one uses a "popular compact form"
of this trick
a ^= b ^= a ^= b;
This variant is invalid from C/C++ point of view (produces undefined
behavior), which might manifest itself in the form of the "incorrect"
assembly code like the one you provided in your example.
However, when the variable modifications are properly separated by
sequence points (as in your C code), this trick is supposed to work
(ignoring the potential overflow issue). If your compiler generates such
assembly code even in this case, then the compiler must be broken.
--
Best regards,
Andrey Tarasevich
- Posted by Aly on April 28th, 2008
"Chris H" <chris@phaedsys.org> wrote in message
news:Jnm0$EIYJHFIFAQl@phaedsys.demon.co.uk...
Sounds like a serious common sense defect to me..
Chris Hills
Technical Director
PhaedruS SystemS Ltd
96 Brambling,
Tamworth, B77 5Pg
UNITED KINGDOM
Tel : 01827 285258
- Posted by andrew.nesterov@softhome.net on April 29th, 2008
On Apr 26, 6:12 am, "DaveN" <Da...@DaveN.COM> wrote:
I like the xor method. The second add sub method also can be done in
three ops,
(no mpy is needed, btw!):
x = x + y
y = x - y
x = x - y
--
Andrew
- Posted by andrew.nesterov@softhome.net on April 29th, 2008
On Apr 26, 4:05 pm, Robert Adsett <s...@aeolusdevelopment.com> wrote:
I've seen even much more in production codes. A good reference is e.g.
the Cooley-Tukey
algorithm. Big things grow out from smaller things. All these little
tricks excercise your brain.
Once I've read a following joke in a programming errs and traps book:
Implement a block that inputs either 1 or 2 and outputs the opposite:
1 -> 2, 2 -> 1
The author continue with three hypotetical solutions:
1. A programming class instructor:
if ( x == 1) x = 2;
if ( x == 2) x = 1;
2. A programmer:
if ( x == 1) x = 2;
else if ( x == 2) x = 1;
3. A mathematitian:
x = 3 - x;
Cheers,
Andrew
- Posted by Chris H on April 29th, 2008
In message <e-6dnULtJfgXo4vVnZ2dnUVZ8tSdnZ2d@bt.com>, Aly
<sf333ddf@sfsss.c> writes
I was commenting on your attitude to social interaction and dealing with
managers etc You appear to have compounded that. I, and I think many
managers would think twice about employing you from you last post.
Managers are there to manage and have different constraints to
programmers. Also their technical expertise may come from a different
area of programming. I once did a smart card project with a project
manager who had come from a UNIX background. Very good project manager
but did not know some of the low level things in smart cards. We had to
explain some of these to him. Armed with the over view and some of the
other significant technical points along with his own experience of
developing he could manage the project very well. Better than any of the
programmers could.
The fact that you have difficulty explaining parts of your work and
interacting with managers is not a good sign. It also appears that you
have little or no understanding of the management role or how to
communicate with managers.
People forget that these days HR often do a search on candidates on the
net. I suppose that is why you use a fake email address? Not prepared
to stand by your own words?
Everyone knows who I am... Been around on line since 1990.
You must be new here.
I don't normally include the company address as is not proper to
advertise on this NG. I could post the full sig I suppose but that would
be a bit much
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
- Posted by DaveN on April 29th, 2008
<andrew.nesterov@softhome.net> wrote in message
news:52d0b962-a520-4f17-881f-f52ab359d2ae@24g2000hsh.googlegroups.com...
Yeah I know now as a couple of people have pointed out! :-) I was so
pleased with myself for working out the method that I didnt't bother to
check if it could be simplified.
--
DaveN
- Posted by Mel on April 29th, 2008
andrew.nesterov@softhome.net wrote:
Another dirty trick -- actually the same: a flag to tell whether succeeding
messages in a serial stream are one byte each or two bytes each (only two
possible cases, but lucky for me the MIDI spec is mature in that regard.)
For 1-byte messages
flag = 0;
for 2-byte messages
flag = -1;
Then for each byte received
flag = -flag;
and flag non-negative means a complete message.
Mel.