Re: [SLUG] [PIG] Guess That Function #1

From: Paul M Foster (paulf@quillandmouse.com)
Date: Mon May 01 2006 - 16:03:34 EDT


Dylan William Hardison wrote:
> I figured every once and a while, someone can post a snippet of code,
> in whatever language they like, and have people try to guess what it
> does.
> Two guidelines: The function's name should be 'f' as to note give away
> its meaning (unless the language in question makes the name 'f'
> impossible), and the language used must be stated.
>
> So, guess what this C-language function does:
> int f(void)
> {
> long one = 1;
> return ! ( *((char *)(&one)) );
> }
>
> I'll give you a hint: It either returns 1 or 0, depending on what you
> compile it on.
>

Okay, I'll bite. I assume the "what" you're talking about in the
sentence above is the platform, either Intel or (older) Mac (and some
other chips). It appears that the function returns the "first" byte (as
a character) of the number assigned to the variable "one". I'm not sure,
but I'm guessing that on an Intel box, it would return a 0, and on a big
endian platform, it would return a 1. So you might be able to say that
this function can tell the user the endianness of a box.

But then again, I could be completely wrong. ;-}

Paul

-- 
Paul M. Foster
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:31:19 EDT