472,982 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

What does this code do?


How about this idea? Post fragments of C code which
seem fun, interesting or instructive. Puzzles can
be posed in various ways. (What does this do? Can you
see the bug? How to code this for better efficiency?
Code for better readability, etc.) Best, perhaps, would
be fragments from another's admirable application.

"What does this do?" puzzles might need comments removed
and symbols obfuscated, as I've done in both of the
following fragments.

Fragments #1 and #2 are unrelated to each other.
Please "reverse-engineer" them before Googl'ing for
exact provenance.

Fragment #1
int hw(uint64 x)
{
uint64 y;

y = x & (x >H0);
if (y & (y >2 * H0))
return 1;
y = x & (x >H1);
if (y & (y >2 * H1))
return 1;
y = x & (x >H2);
if (y & (y >2 * H2))
return 1;
y = x & (x >1);
return (y & (y >2));
}
Fragment #2
void baz(int b, int c)
{
int a, d, e, f, g;

if (e = b, g = a = -1, c)
while (d = b) {
b = c-1, f = c = d;
while (f--)
foo(g -= a);
d = -e, e = a, a = d;
}
}
What does each of these fragments do?

James Dow Allen
Feb 6 '08 #1
9 1944
James Dow Allen wrote:
>
.... snip ...
>
Fragment #1
int hw(uint64 x) {
uint64 y;

y = x & (x >H0);
nothing. H0 is undefined.

.... snip ...
>
Fragment #2
void baz(int b, int c) {
int a, d, e, f, g;

if (e = b, g = a = -1, c)
while (d = b) {
nothing. d is uninitialized.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com

Feb 6 '08 #2
On Wed, 06 Feb 2008 00:20:17 -0500, CBFalconer wrote:
James Dow Allen wrote:
>>
(...)
>>
Fragment #2
void baz(int b, int c) {
int a, d, e, f, g;

if (e = b, g = a = -1, c)
while (d = b) {

nothing. d is uninitialized.
'd' is initialised using input argument 'b' (it is not a comparison to 'b').

- Anand

--
ROT-13 email address to reply.
Feb 6 '08 #3
CBFalconer said:
James Dow Allen wrote:
>>
... snip ...
>>
Fragment #1
int hw(uint64 x) {
uint64 y;

y = x & (x >H0);

nothing. H0 is undefined.
Chuck, don't you think James *knows* he hasn't defined H0? He's not exactly
J Random Newbie.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Feb 6 '08 #4
Anand Hariharan wrote:
CBFalconer wrote:
>James Dow Allen wrote:
>>>
(...)
>>>
Fragment #2
void baz(int b, int c) {
int a, d, e, f, g;

if (e = b, g = a = -1, c)
while (d = b) {

nothing. d is uninitialized.

'd' is initialised using input argument 'b' (it is not a
comparison to 'b').
Woops - you're right.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Feb 6 '08 #5
In article <Ab******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>CBFalconer said:
>James Dow Allen wrote:
>>>
... snip ...
>>>
Fragment #1
int hw(uint64 x) {
uint64 y;

y = x & (x >H0);

nothing. H0 is undefined.

Chuck, don't you think James *knows* he hasn't defined H0? He's not exactly
J Random Newbie.
Oh. The. Irony.

Note that recently the regs are getting more and more open (and openness
is a good thing - don't get me wrong!) about the fact that there are
different rules for the Clique than for, as RH so quaintly puts it, J
Random Newbie.

Note also that CBF's Clique membership seems to be in a probationary
status these days...

Feb 6 '08 #6
ga*****@xmission.xmission.com (Kenny McCormack) writes:
In article <Ab******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>CBFalconer said:
>>James Dow Allen wrote:

... snip ...

Fragment #1
int hw(uint64 x) {
uint64 y;

y = x & (x >H0);

nothing. H0 is undefined.

Chuck, don't you think James *knows* he hasn't defined H0? He's not exactly
J Random Newbie.

Oh. The. Irony.

Note that recently the regs are getting more and more open (and openness
is a good thing - don't get me wrong!) about the fact that there are
different rules for the Clique than for, as RH so quaintly puts it, J
Random Newbie.

Note also that CBF's Clique membership seems to be in a probationary
status these days...
"Chuck" is probably one of the most useless posters to a Usenet
technical group I have ever witnessed. No wonder his code is so awful -
I doubt if he was ever allowed to post in a real team as I have rarely
seen anyone so antisocial and up themselves. Better to killfile him,
much as a I abhor doing so.

Feb 6 '08 #7
Re: What does this code do?

Decrease productivity of newsgroup readers ? :-)
Feb 7 '08 #8
On Feb 9, 5:51 am, Dave Hansen <i...@hotmail.comwrote:
On Feb 8, 3:12 am, James Dow Allen <jdallen2...@yahoo.comwrote:
[...]
Richard Bos wrote:
that I can't be bothered to figure out.
He didn't say he couldn't, but that he couldn't be bothered.
Apparently he's decided it's beneath him.

But I like a puzzle. I'm thinking "spiral..."
Yes, with a nearby spiralling thread I'm surprised
only Dave got this. It would be interesting to
know why Bos disliked the code so much. (Omission
of comments was deliberate.) I don't generally pack
multiple statements onto one line, but did so
almost whimsically in the fragment. Avoiding
new lines seems not too egregious in simple idioms like
d = e, e = a, a = d; /* swap */

All other things being equal (though of course
they never are!) the succincter code is the better
code: one FOR is better than four FOR's. For this
reason, my spiraller seems OK.

James
Feb 11 '08 #9
In article <47*****************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote:
....
>Get off your friggin' high horse, mister perfect-maths-wizard. You have
not the slightest idea how I tested your program wand why I could not be
arsed to do more of an effort. But since you asked for it, I'll tell you
now: I couldn't be arsed because it was crappy code, used in a crappy
puzzle, by a crappy programmer who should have known better than to
consider that crap even remotely acceptable. And in the future, I won't
even be making what little effort I have this time; your programming
inadequacy is not worth it.
Somebody did not get enough mommy love.

Feb 12 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
3
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
3
by: mark | r | last post by:
is there an industry standard method of costing out a project the problem i have is that when talking to a developer they say "i dont know how long it will take" which just isnt acceptable #...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
35
by: GTO | last post by:
I do not believe that C# is the future of C++. I also do not believe that adding two thousand new library functions to the standard library is the future of C++. But what is the future of C++? Is...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.