*BSD News Article 9164


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA5276 ; Wed, 23 Dec 92 04:01:26 EST
Xref: sserve comp.lang.c:37065 comp.unix.bsd:9221
Path: sserve!manuel.anu.edu.au!munnari.oz.au!hp9000.csc.cuhk.hk!saimiri.primate.wisc.edu!sdd.hp.com!spool.mu.edu!yale.edu!ira.uka.de!Germany.EU.net!rrz.uni-koeln.de!unidui!du9ds3!veit
From: veit@du9ds3.fb9dv.uni-duisburg.de (Holger Veit)
Newsgroups: comp.lang.c,comp.unix.bsd
Subject: Re: Segmentation faults
Date: 21 Dec 92 08:11:12 GMT
Organization: Uni-Duisburg FB9 Datenverarbeitung
Lines: 36
Message-ID: <veit.724925472@du9ds3>
References: <1gricmINNsl@ub.d.umn.edu> <1992Dec18.134225.20548@Logix.DE>
Reply-To: veit@du9ds3.fb9dv.uni-duisburg.de
NNTP-Posting-Host: du9ds3.fb9dv.uni-duisburg.de

In <1992Dec18.134225.20548@Logix.DE> jpm@Logix.DE (Jan-Piet Mens) writes:

>In <1gricmINNsl@ub.d.umn.edu> cbusch@ub.d.umn.edu (Chris) writes:
>>    Why is the following code producing a segmentation fault???
>>I am compiling this code on an Encore Multimax running UMAX 4.3 Unix.

>Doesn't matter where you compile it is bad anyway...

>void writexy(x,y,s)
>int x, y;
>char *s;				/* OTHERWISE DEFAULTS TO int !!! */
>{
>   printf("\33[%d;%dH%s",y,x,s);
>}

>[ BTW, how about termcap/terminfo ? ]
>-- 
>    __  _____   __  __ 
>   |  ||  _  \ |  \/  |    Logix GmbH                             jpm@Logix.DE
> __|  ||  ___/ |      |    Moritzstrasse 50, +49-611-309797   jpm@logixwi.UUCP
>|_____||__|    |__||__|    D-6200 Wiesbaden  ...!uunet!mcsun!unido!logixwi!jpm

This is a real problem where sizeof(int) != sizeof(char*), for instance with
Turbo C or Microsoft C or similar 16bit junk. But if you compile this
with a 32bit K&R compiler, and sizeof(int)==sizeof(char*) (=4), it won't see 
a difference, because it will just take 32bit from the parameter stack 
and push it as a 32bit argument to printf.
The compiler cannot find out the real expected type (it cannot do parsing
of the format string in general!).

Holger
-- 
|  |   / Dr. Holger Veit         | INTERNET: veit@du9ds3.fb9dv.uni-duisburg.de
|__|  /  University of Duisburg  |
|  | /   Dept. of Electr. Eng.   |          "Understand me correctly:
|  |/    Inst. f. Dataprocessing |     I'm NOT the WIZARD OF OS" (Holger)