[comp.unix.xenix] uPort 1.3 cc static char *

jrb@petro.UUCP (Jon Boede) (11/16/87)

I sent some code over to an AT running Microport XENIX 1.3 ... when using the
-Ml (large) model the following crashed and burned...

main()
{
	char *a_pointer;

	a_pointer = "some static data";

	puts(a_pointer);
}

However, when I change a_pointer to "static char *a_pointer" it works.  Why?

Thanks,
Jon
-- 
Jon Boede	...!{gatech,ihnp4,ssbn,swrinde,tness1,utanes}!petro!jrb
512/599-1847                           2555 N.E. Loop 410, #1403, 78217
	"People who are incapable of making decisions are
	 the ones who hit those barrels at freeway exits."

root@uwspan.UUCP (11/18/87)

+---- jrb@petro.UUCP (Jon Boede) writes in <471@petro.UUCP> ----
| I sent some code over to an AT running Microport XENIX 1.3 ... when using the
| -Ml (large) model the following crashed and burned...
| main() {
| 	char *a_pointer;
| 	a_pointer = "some static data";
| 	puts(a_pointer);
| }
| However, when I change a_pointer to "static char *a_pointer" it works.  Why?
+----

First of all, the Microport System5r2 port is *not* XENIX :-),
Secondly it does NOT crash and burn on my system.
(Configuration: Prog dev 1.3 and DosMerge 2.3 kernel, 4 users on at the time,
 3Mb RAM, 140Mb disk space...)

Saved this file as x.c, edited off the message text,
Compiled with: "cc -o x -Ml x.c" (no warning or error messages)
run as:        "./x"
output:        "some static data"	(quotes are mine)


-- 
Email to unix-at-request@uwspan with questions about the newsgroup unix-at,
otherwise mail to unix-at@uwspan with a Subject containing one of:
	    386 286 Bug Source Merge or "Send Buglist"
(Bangpath: rutgers!uwvax!uwspan!unix-at & rutgers!uwvax!uwspan!unix-at-request)

jackg@hpisoa2.HP.COM (Jack Gerson) (11/18/87)

> / hpisoa2:comp.unix.xenix / jrb@petro.UUCP (Jon Boede) /  5:51 am  Nov 16, 1987 /
> I sent some code over to an AT running Microport XENIX 1.3 ... when using the
> -Ml (large) model the following crashed and burned...
> 
> main()
> {
> 	char *a_pointer;
> 
> 	a_pointer = "some static data";
> 
> 	puts(a_pointer);
> }
> 
> However, when I change a_pointer to "static char *a_pointer" it works.  Why?
> 
> Thanks,
> Jon
> -- 
> Jon Boede	...!{gatech,ihnp4,ssbn,swrinde,tness1,utanes}!petro!jrb
> 512/599-1847                           2555 N.E. Loop 410, #1403, 78217
> 	"People who are incapable of making decisions are
> 	 the ones who hit those barrels at freeway exits."
> ----------

You didn't allocate memory for your character array, so it's no surprise
your process crashed.

How did you do the static allocation?  If you said

	static char *a_pointer = "some static data"

your declaration itself allocated space for the array.

daveb@laidbak.UUCP (Dave Burton) (11/18/87)

In article <471@petro.UUCP> jrb@petro.UUCP (Jon Boede) writes:
>I sent some code over to an AT running Microport XENIX 1.3 ... when using the
>-Ml (large) model the following crashed and burned...
>
>main()
>{
>	char *a_pointer;
>	a_pointer = "some static data";
>	puts(a_pointer);
>}
>
>However, when I change a_pointer to "static char *a_pointer" it works.  Why?

I
would
also
like
to
know
the
answer
to
this.
(Take that, included text line counter!)
-- 
--------------------"Well, it looked good when I wrote it"---------------------
 Verbal: Dave Burton                        Net: ...!ihnp4!laidbak!daveb
 V-MAIL: (312) 505-9100 x325            USSnail: 1901 N. Naper Blvd.
#include <disclaimer.h>                          Naperville, IL  60540

janm@runx.ips.oz (Jan Mikkelsen) (11/22/87)

I suggest you contact
Microport about upgrading to 2.3! (How old is 1.3 anyway?)
 
					Jan.


ACSnet: janm@runx.ips.oz		JANET:	runx.ips.oz!janm@ukc
ARPA:   janm%runx.ips.oz@seismo.css.gov	CSNET:	janm@runx.ips.oz
UUCP:   {enea,hplabs,mcvax,prlb2,seismo,ubc-vision,ukc}!munnari!runx.ips.oz!janm

"He's dead, icici5

chris@mimsy.UUCP (Chris Torek) (11/22/87)

<In article <471@petro.UUCP> jrb@petro.UUCP (Jon Boede) notes
<>... when using the -Ml (large) model the following crashed and burned...
<>
<>main()
<>{
<>	char *a_pointer;
<>
<>	a_pointer = "some static data";
<>
<>	puts(a_pointer);
<>}
<>
<>However, when I change a_pointer to "static char *a_pointer" it works.  Why?

In article <1120001@hpisoa2.HP.COM> jackg@hpisoa2.HP.COM (Jack Gerson) writes:
>You didn't allocate memory for your character array, so it's no surprise
>your process crashed.

Nope.  Quoted strings ("some static data") are put by the compiler into
some initialised space (text or data); the `value' of such an expression
is a pointer of type `(char *)' which points to the first character of
the string.

In other words, if the program shown above crashes, the compiler
or support library is broken.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

jmsully@admin.UUCP (John M. Sully) (12/01/87)

In article <1253@laidbak.UUCP| daveb@laidbak.UUCP (Dave Burton) writes:
|In article <471@petro.UUCP| jrb@petro.UUCP (Jon Boede) writes:
||I sent some code over to an AT running Microport XENIX 1.3 ... when using the
||-Ml (large) model the following crashed and burned...
||
||main()
||{
||	char *a_pointer;
||	a_pointer = "some static data";
||	puts(a_pointer);
||}
||
||However, when I change a_pointer to "static char *a_pointer" it works.  Why?

Well, I compiled this here at Microport (we're still shipping the 1.3 cc) and
it worked fine in both large and small model.  The command line I used was:
	cc -Ml bug.c
when I typed a.out, it ran! :-)