Re: Sun Studio 11: C++ 5.8 Compiler



On Mon, Apr 16, 2007 at 01:22:07AM -0000, neelabhsharma1@xxxxxxxxx wrote:
As per the specifications the compiler should be based on C99. But i think it still does not handle the function call strtoll(). This issue did not arise with RHL 9.0

If it did the handling properly then the result of the program should not be 0.


/*Snippet of the Code */
#include<stdio.h>
#include<stdlib.h>

int main()
{
char *a = "89abcdef";
long long int c;
a[8] = '\0';
c = strtoll(a, NULL, 16);
printf("the num is %8x", c);
return 0;
}


My understanding of the OS, Platform (SPARC), ofcourse C is just of a beginner and am eager to learn, please provide supporting comments..


This is consistent with Sun WorkShop 6 and gcc 3.4.2 (Both on Solaris/Sparc).
Gcc 3.4.5 on Linux (Intel) appears to do what you were expecting, but actually
does not. If you change the "char a..." definition to a hex value longer than
8 characters you will not see the last 8 characters on Sparc. On Intel you will
only see the last 8 characters. This is due to differences in byte ordering on
these processors.

The problem is in your printf format. %8x expects to print something of type
"int". Most current compilers specify type "int" to be the same as "long int"
which is 32 bits. "long long int" is 64 bits. What is happening here is you
are printing the first 32 bits of the argument. If you use the correctly
typed format string "%8llx", you should see the correct value printed in all
cases.

I hope this helps your understanding of what has happened here.


Steven Leikeim

--

Steven Leikeim, GSEC-Gold | We, the willing
Department of Electrical and Computer | led by the unknowing
Engineering | are doing the impossible
Schulich School of Engineering | for the ungrateful.
University of Calgary | We have done so much
Calgary, Alberta | for so long with so little
| we are now qualified
Phone: (403) 220-5373 Fax: (403) 282-6855 | to do anything with nothing.



Relevant Pages

  • Re: Checking for a keypress on Linux ?????
    ... the short delay in kbhit() ... > int getch; ... > * returns the number of characters available to read. ... > static struct termios Otty, ...
    (comp.os.linux.development.apps)
  • Re: [PATCH] Fix console utf8 composing
    ... So, the result is that the result of the composing operation is still taken from the accent_table, and thus cannot be more than "unsigned char" allows. ... in UTF-8 mode, it is possible to generate characters from Latin-1 set by composing, and they are generated correctly. ... +static int use_unicode; ...
    (Linux-Kernel)
  • Re: [PATCH] console UTF-8 fixes
    ... as substitute glyph ... don't ignore zero-width characters (except for a few zero-width spaces ... print an extra space for double-wide characters for the cursor to stand ... int first; ...
    (Linux-Kernel)
  • Re: Get ASCII value for character when higher than 127
    ... The reason I want to store the int-values for the characters in stead ... I also imagined, that if I have the int value, I can perform some ... char timeString; ... strcat; ...
    (microsoft.public.vc.language)
  • Re: Get ASCII value for character when higher than 127
    ... The reason I want to store the int-values for the characters in stead ... I also imagined, that if I have the int value, I can perform some ... char timeString; ... strcat; ...
    (microsoft.public.vc.language)