[comp.lang.c] C

daveb@geac.UUCP (David Collier-Brown) (04/27/88)

In article <1988Apr24.004842.3251@utzoo.uucp>, henry@utzoo.uucp (Henry Spencer) writes:
|  Remember that there are two separate issues here:  what you write, and the
|  code the compiler generates for it.  With modern compilers, the two are
|  often quite different.

In article <2606@ttrdc.UUCP> levy@ttrdc.UUCP (Daniel R. Levy) writes:
| This may be highly undesireable in a language used for programming operating
| systems, where the programmer needs something approaching WYSIWYG capability.
| C is eminently such a language.

  Well, C is probably the best current choice for that language (I
learned on FORTRAN II: now **there's** a WYSIWYG language).
  Regrettably, C is a high-level language, and certain optimizations
are perfectly reasonable if one is a human writing non-special code
in it.  They are less reasonable if you are generating C from a
higher-level language, and much less so if you are writing device
drivers.

  This dichotomy has been discussed before (but I forget who to
cite! mea culpa).

  Therefor I raise the question:


			Do we need C--?


  C-- is WYSIWYG C, and is explicitly intended for the following
purposes:
	1) writing critical machine-specific functions,
	2) as a target of source-to-source transformers (including
	   certain classes of optimizers),
	3) as a target for VHLLs, including C++, database
	   embedded-SQL processors, ML and Ada(tm).

  I'm working with people using I-SQL, and want to implement an ML:
I need predictable behavior, but can live with some forms of
optimization (notably code motions, constant folding and the like).
  In fact, I could handle any (correctness preserving!)
source-to-source transformation so long as I could ask for the
generated output to read.

  What say others?

--dave (ah, if only I had my 1130/1800 back) c-b
-- 
 David Collier-Brown.                 {mnetor yunexus utgpu}!geac!daveb
 Geac Computers International Inc.,   |  Computer Science loses its
 350 Steelcase Road,Markham, Ontario, |  memory (if not its mind) 
 CANADA, L3R 1B3 (416) 475-0525 x3279 |  every 6 months.

ken@aiva.ed.ac.uk (Ken Johnson) (04/29/88)

In article <2665@geac.UUCP> daveb@geac.UUCP (David Collier-Brown) writes:

>Do we need C--?

...pronounced `C diminished', perhaps? :-)
-- 
------------------------------------------------------------------------------
From Ken Johnson, AI Applications Institute, The University, EDINBURGH
Phone 031-225 4464 ext 212
Email k.johnson@ed.ac.uk

chris@mimsy.UUCP (Chris Torek) (05/01/88)

>In article <2665@geac.UUCP> daveb@geac.UUCP (David Collier-Brown) writes:
>>Do we need C--?

In article <389@aiva.ed.ac.uk> ken@aiva.ed.ac.uk (Ken Johnson) writes:
>...pronounced `C diminished', perhaps? :-)

But then obviously we need C--7 too; if it is to be a standard, though,
we must wait for 2007.  And who will standardise Cmaj7?
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

mls@whutt.UUCP (SIEMON) (05/02/88)

In article <11299@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes:
> 
> In article <389@aiva.ed.ac.uk> ken@aiva.ed.ac.uk (Ken Johnson) writes:
> >...pronounced `C diminished', perhaps? :-)
> 
> But then obviously we need C--7 too; if it is to be a standard, though,
> we must wait for 2007.  And who will standardise Cmaj7?

"No, no, no, you're wrong"  It REALLY should be pronounced "H".

-- 
Michael L. Siemon
contracted to AT&T Bell Laboratories
ihnp4!mhuxu!mls
standard disclaimer

yphotons@athena.mit.edu (Sun Warrior) (02/28/89)

I would like to know how to set an array (float) to a certain size
normally I would have done it like this

float array [size]

but the thing is I would first like to be able to type in the size and
then set the array . I tried this by using scanf statement and then
the float but that did not work. help

yphotons@athena.mit.edu

bs@linus.UUCP (Robert D. Silverman) (02/28/89)

In article <9501@bloom-beacon.MIT.EDU> yphotons@athena.mit.edu (Sun Warrior) writes:
:
:I would like to know how to set an array (float) to a certain size
:normally I would have done it like this
:
:float array [size]
:
:but the thing is I would first like to be able to type in the size and
:then set the array . I tried this by using scanf statement and then
:the float but that did not work. help
:
:yphotons@athena.mit.edu


This is rather easy. Declare 'array' to be a pointer to a float, then
call malloc to allocate the memory space. e.g.

float *array

array = (float*) malloc(size* sizeof(float));

etc.

Bob Silverman

henry@utzoo.uucp (Henry Spencer) (03/01/89)

In article <9501@bloom-beacon.MIT.EDU> yphotons@athena.mit.edu (Sun Warrior) writes:
>I would like to know how to set an array (float) to a certain size...
>... I would first like to be able to type in the size and
>then set the array...

You can't.  With certain (unhelpful) exceptions, the dimensions of C arrays
must be constants.  You can get much the same effect using malloc() and
pointers, although it is more complicated.
-- 
The Earth is our mother;       |     Henry Spencer at U of Toronto Zoology
our nine months are up.        | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

gwyn@smoke.BRL.MIL (Doug Gwyn ) (03/01/89)

In article <9501@bloom-beacon.MIT.EDU> yphotons@athena.mit.edu (Sun Warrior) writes:
>I would like to know how to set an array (float) to a certain size
>normally I would have done it like this
>float array [size]
>but the thing is I would first like to be able to type in the size and
>then set the array . I tried this by using scanf statement and then
>the float but that did not work. help

There must be some conceptual confusion here, because "setting the
size of an array" is not a C concept.
	float array[N];
declares that the name "array" denotes an array of N contiguous elements,
each element of type float.  The dimension N is used only to allocate
sufficient storage for N elements; you don't have to actually use them
all.  Thus one solution is to simply declare the array larger than you'll
ever need it to be, and keep track of the presumed valid size in a
separate integer variable (use that for loop limits, etc. in the code).
C does not permit N to be a variable in an array declaration; it must be
an integer constant [expression].

You can also obtain a pointer to storage sufficiently large to hold N
contiguous `float' elements via a call to the malloc() function:
	extern char *malloc();	/* void* for ANSI C */
	float *arrayp = (float *)malloc( N * sizeof(float) );
Here, N can be and often is a variable determined at run time.  In this
example, "arrayp" is NOT an array of N floats, but can be treated as
a pointer to the first member of such an array; therefore "arrayp"
can be used in most of the same contexts as those in which "array" might
have been used ("sizeof array" being the most notable exception).  That's
because C converts the name of an array "array" into a pointer to its
first element (similar to "arrayp") when it is used in most expressions.
Thus, "arrayp[i]" acts just like "array[i]" (it is the i+1st float in the
array; remember that C indexing starts at 0, not 1).

awd@dbase.UUCP (Alastair Dallas) (03/07/89)

In article <1989Feb28.170504.17123@utzoo.uucp>, henry@utzoo.uucp (Henry Spencer) writes:
> In article <9501@bloom-beacon.MIT.EDU> yphotons@athena.mit.edu (Sun Warrior) writes:
> >I would like to know how to set an array (float) to a certain size...
> >... I would first like to be able to type in the size and
> >then set the array...
> 
> You can't.  With certain (unhelpful) exceptions, the dimensions of C arrays
> must be constants.  You can get much the same effect using malloc() and
> pointers, although it is more complicated.

It's not very complicated at all:

	float *p;
	int i;
	int n;

	printf("Enter the size of the array:");
	scanf("%d", &n);
	p = (float *) calloc(n, sizeof(float));
	
	for (i=0; i<n; i++)
		p[i] = 0.0;

	...

	free(p);

What's the big deal?

/alastair/

henry@utzoo.uucp (Henry Spencer) (03/09/89)

In article <27@dbase.UUCP> awd@dbase.UUCP (Alastair Dallas) writes:
>> ... the dimensions of C arrays
>> must be constants.  You can get much the same effect using malloc() and
>> pointers, although it is more complicated.
>
>It's not very complicated at all...
>...
>What's the big deal?

I didn't say "very complicated", I said "more complicated".  Understanding
pointers and malloc() is a significant hurdle for a beginner.
-- 
The Earth is our mother;       |     Henry Spencer at U of Toronto Zoology
our nine months are up.        | uunet!attcan!utzoo!henry henry@zoo.toronto.edu