Re: [gtk-list] unary minus operator applied to unsigned type,result still unsigned



On Tue, 16 Feb 1999, Tor Lillqvist wrote:

> Micrsoft's compiler gives the warning in the Subject when compiling
> various GTk+ files. I have previously ignored them, but now I thought
> maybe it's best to ask if they might be a sign of some bugs lurking in
> the code...
> 
> For instance, the following lines in gtktext.c cause that warning:
> (line numbers from my current win32 codebase, approximate for the CVS
> version)
> 
> 1109:
>     move_mark_n (&text->cursor_mark, 
> 		 -MIN(nchars, text->cursor_mark.index - text->point.index));
>   
> 1491:
>   gdk_gc_set_ts_origin (text->bg_gc,
> 			(- text->first_onscreen_hor_pixel + xthick) % width,
> 			(- text->first_onscreen_ver_pixel + ythick) % height);
> 
> 3579:
>       scroll_int (text, - LINE_HEIGHT(CACHE_DATA(text->line_start_cache->next)));
> 
> 3625:
>   gint pixels = - text->first_cut_pixels;
> 
> 3822:
>   pixel_height = - text->first_cut_pixels;
> 
> --tml


uhm, i'd actually expect every ansi compliant compiler to auto cast such results
into a signed range. could you give the output of

#include <stdio.h>
int
main ()
{
  unsigned short s = 5;
  double d = - s;

  printf ("- %u = %f \n", s, d);

  return 0;
}

this compiles cleanly with gcc on my box and gives:
$ gcc -Wall -ansi -pedantic unary-minus.c && ./a.out
- 5 = -5.000000

if this yields anything else than -5.000000 on windows, we eventually have
to adapt those code portions (or find a compiler switch to make microsoft's
compiler behave sanely ;).

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]