[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] long gcc vs. cc



In <sslug@sslug> "Martin Møller Pedersen" <sslug@sslug> writes:

>  Jeg har arvet noget gammel kode, som var udviklet til at virke med diverse
>platforme, men ikke gcc på solaris, hvilket var min opgave.

>Hvorfor virkede flg. ikke ?

>  int      left_over;
>  long vol_bytes

>[...]
>        if ( (vol_bytes - left_over < 0) && left_over > 0 ) /* eof */

>men skulle erstattes af

>       #if TARGET_OS == SOLARIS
>        if ( ((long)left_over > vol_bytes ) && left_over > 0) /* eof */
>        #else
>        if ( (vol_bytes - left_over < 0) && left_over > 0 ) /* eof */
>        #endif

>for at virke med gcc/solaris ?


Hvilket test-scenarie virker det ikke med (altså: hvilke værdier af
left_over og vol_bytes) ?

Da sizeof(int) og sizeof(long) er identisk med gcc på Solaris (begge er 
32 bit), så kan jeg ikke se hvorfor det skulle ikke skulle virke. Og
en lille test-udgave af dit program giver også det resultat jeg forventede:

$ uname -a
SunOS my.host.dk 5.8 Generic_117350-36 sun4u sparc SUNW,UltraAX-i2 Solaris
$ cat t1.c
#include <stdio.h>

int main(int argc, char *argv[])
{
	int left_over;
	long vol_bytes;

	left_over = 1;
	vol_bytes = 0;

	printf("int is %d bytes, long is %d bytes\n", sizeof(left_over), sizeof(vol_bytes));

	if ( (vol_bytes - left_over < 0) && left_over > 0 ) {
		printf("EOF\n");
	}
	else {
		printf("Not EOF\n");
	}

	return 0;
}

$ gcc -Wall -pedantic t1.c
$ ./a.out
int is 4 bytes, long is 4 bytes
EOF


Det er med gcc 3.3.2.


Mvh,
Henrik



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-06-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *