Re: little endian or big endian ???



On Jun 29, 6:51 am, Spade <strangerdr...@xxxxxxxxx> wrote:
On Jun 29, 3:22 pm, r...@xxxxxxxxxxxxxxxxxxxxxx (Richard Bos) wrote:





Tejas Kokje <binarysemaph...@xxxxxxxxx> wrote:
On Jun 28, 12:01 pm, guthena <r4r...@xxxxxxxxx> wrote:
Write a small C program to determine whether a machine's type is
little-endian or big-endian.

Here you go..

int main()
{
int num=1;
char *cptr;

cptr = (char *)&num;

if (*cptr)
printf ("little endian\n");
else
printf ("big endian\n");

return 0;
}

Which company interview question is this ? :-D

Congratulations. You just did his homework for him. Since it's a crappy
assignment,

This most probably isn't a homework question. Its a typical question
thats asked mostly in interviews in India.


Which makes it all the more depressing, both that an interviewer would
bother to ask it and that the candidate would need help finding the
answer. If you don't at least have a rough idea of how to figure this
out by the time you're looking for a job, you shouldn't be looking for
a job yet.

As worded, though, this sounds like a typical intro programming
assignment.

his teacher probably thinks he did a sterling job, he'll
probably pass the course on the back of your work, and he'll end up
holding a job as a programmer _still_ thinking that this is a good
program. Which it is not; it is flawed for several reasons.

Can you tell me how it is flawed? Is it because of casting from int*
to char*

It would miss weird things like VAX floats, which were "middle-
endian" (byte order 2301).

.



Relevant Pages

  • [Hat-Squad] Computer-Associates, License Manager POC Exploit
    ... by the way, sending up this bad char to the bottom of what you know of some amazing wannabel33t deface kiddies crawling my website, ... void usage; ... printf(" reverse a cmdshell on your listener. ...
    (Bugtraq)
  • Re: int pointers & characters !!
    ... printf is expecting a char. ... At this point, if there is no padding in the passed values, printf will ... advance it's arg pointer by one byte - but the value you passed was 4 ... and in your example char is promoted to int. ...
    (comp.lang.c)
  • Re: *str++ is undefined?
    ... But the act of actual assignment consists of one and only ... call in the destination object of type 'char'. ... char res = tolower; ... Or it can be evaluated in accordance with a different schedule ...
    (comp.lang.c)
  • Re: making bytes out of bits
    ... Since the compiler told you the code was broken, ... char a; ... schwartz2.c:17: warning: suggest parentheses around assignment used as ...
    (comp.lang.c)
  • Re: Return value of assignment operator
    ... Following printf prints 3. ... The 2nd argument to the printfcall is the assignment expression ...
    (comp.lang.c)