🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6410

2.7.1: warning casting short to pointer

#6410
From: Stephen Gildea
Date: Mon, 27 Nov 1995 00:00
38 lines
1497 bytes
Why does gcc complain when casting a short to a pointer?
What rule is being violated here?  Casting an int to a pointer
succeeds without warning (on a Sparc).


$ cat ptr-cast.c
/* ptr-cast.c - test casting short to pointer with gcc */

int func()
{
    unsigned int i = 0;
    unsigned short s = 0;
    void *p, *q;
    
    p = (void*)i;
    q = (void*)s;

    return p<q;
}

$ gcc -c ptr-cast.c
ptr-cast.c: In function `func':
ptr-cast.c:10: warning: cast to pointer from integer of different size
$ gcc -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.1/specs
gcc version 2.7.1


What am I supposed to do about this warning?  I didn't see any
discussion of it in the manual.

It is not clear how I can write code that stores a short in a pointer
type and makes gcc happy.  Since pointers are of different sizes on
different architectures, there is no type I can cast my short to so
that I'm sure it is the right size and that subsequently casting it to
a pointer won't produce a warning.

 < Stephen
Technical Details
Message-ID: <9511271727.AA14868@alex.x.org>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,991b7802ac55bf58,start
X-Google-Attributes: gid113d02,public
From: gildea@x.org (Stephen Gildea)
Subject: 2.7.1: warning casting short to pointer
Date: 1995/11/27
Message-ID: <9511271727.AA14868@alex.x.org>
X-Deja-AN: 120236559
distribution: gnu
sender: daemon@cis.ohio-state.edu
organization: X Consortium, Cambridge, Massachusetts
newsgroups: gnu.gcc.bug