Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: why cant fu...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 42 of 157 Topic 25604 of 27343
Post > Topic >>

Re: why cant functions return arrays

by Keith Thompson <kst-u@[EMAIL PROTECTED] > Apr 19, 2008 at 08:32 PM

"sanjay.vasudevan@[EMAIL PROTECTED]
" <sanjay.vasudevan@[EMAIL PROTECTED]
> writes:
> Keith Thompson wrote:
[...]
>> Assume that f is a function that returns an array of int.  Presumably
>> you'd want to be able to do something like this:
>>
>>     int arr[100];
>>     arr = f();
>>
>> What if f returns an array of 90 ints?  Or 200?  Do you reject it at
>> compile time?  If so, you have to decide when writing the f *exactly*
>> how many elements it's going to return; that's far less flexible than
>> C's current (admittedly unwieldy) mechanisms.  Or do you reject it
>> during execution?  If so, how?  Do you introduce an exception
>> mechanism?  Do you just say it's undefined behavior?  Or do you copy
>> just part of the array?
>
> The following code gives a type mismatch error:
> int a[90];
> int (*b)[100];
> b = &a;
>
> doesnt this mean that there exists a restriction on array address
> assignment based on size.

Yes.  int[90] and int[100] are two distinct types; that's the problem.

It's actually not that much of a problem in C as it currently exists,
because we have other ways of working with arrays of arbitrary length:
we typically work with a pointer to the first element and some
programmer-defined technique of tracking the length.  Which means that
it's entirely up to the programmer to make sure array lengths match
when they need to.

> so, we cud allow functions to return arrays(as a first-class type) of
> known size (althogh as u mentioned, this is quite restrictive) and
> allow assigning only to same size arrays.

Right, and IMHO it wouldn't be worth it, because it would be so
inflexible.

<OT>
In Ada, you can declare an array type that leaves the dimensions
unspecified.  By specifying the dimensions, you create a *subtype*.
All subtypes of the same type are compile-time compatible, but
operations are checked at run time.  The languages operations are
sufficiently powerful (including passing arbitrary arrays as
parameters with full type checking, returning arbitrary arrays from
functions, and a built-in array slicing operation) to make this
workable.  I don't believe something like this could be added to C
without altering the feel of the language.
</OT>

> of course "int f()[];"  neednt be allowed.
>
> and this treatment as a first-class type would break existing code.

Yes.

-- 
Keith Thompson (The_Other_Keith) <kst-u@[EMAIL PROTECTED]
>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
 




 157 Posts in Topic:
why cant functions return arrays
"sanjay.vasudevan@[E  2008-04-14 14:25:11 
Re: why cant functions return arrays
roberson@[EMAIL PROTECTED  2008-04-14 21:41:05 
Re: why cant functions return arrays
jacob navia <jacob@[EM  2008-04-14 23:54:54 
Re: why cant functions return arrays
"Bartc" <bc@  2008-04-14 21:57:20 
Re: why cant functions return arrays
jacob navia <jacob@[EM  2008-04-14 23:59:17 
Re: why cant functions return arrays
richard@[EMAIL PROTECTED]  2008-04-14 22:56:12 
Re: why cant functions return arrays
"Default User"   2008-04-14 23:19:54 
Re: why cant functions return arrays
Eric Sosman <esosman@[  2008-04-15 08:44:29 
Re: why cant functions return arrays
"Dik T. Winter"  2008-04-15 01:15:20 
Re: why cant functions return arrays
"Dik T. Winter"  2008-04-15 01:12:54 
Re: why cant functions return arrays
Jack Klein <jackklein@  2008-04-14 21:59:34 
Re: why cant functions return arrays
jacob navia <jacob@[EM  2008-04-14 23:55:21 
Re: why cant functions return arrays
Jack Klein <jackklein@  2008-04-14 22:01:40 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-18 00:09:20 
Re: why cant functions return arrays
user923005 <dcorbit@[E  2008-04-14 15:36:58 
Re: why cant functions return arrays
Ben Bacarisse <ben.use  2008-04-14 23:43:58 
Re: why cant functions return arrays
Hallvard B Furuseth <h  2008-04-15 01:00:20 
Re: why cant functions return arrays
"Bartc" <bc@  2008-04-14 23:55:07 
Re: why cant functions return arrays
Hallvard B Furuseth <h  2008-04-15 15:36:25 
Re: why cant functions return arrays
jacob navia <jacob@[EM  2008-04-15 16:25:56 
Re: why cant functions return arrays
"Bartc" <bc@  2008-04-15 17:42:24 
Re: why cant functions return arrays
Hallvard B Furuseth <h  2008-04-16 17:07:25 
Re: why cant functions return arrays
Shirsoft <shirsoft@[EM  2008-04-15 00:39:07 
Re: why cant functions return arrays
"Bartc" <bc@  2008-04-17 09:23:14 
Re: why cant functions return arrays
John Bode <john_bode@[  2008-04-15 12:25:29 
Re: why cant functions return arrays
jacob navia <jacob@[EM  2008-04-15 22:56:36 
Re: why cant functions return arrays
Eric Sosman <esosman@[  2008-04-15 21:25:36 
Re: why cant functions return arrays
"Dik T. Winter"  2008-04-16 10:42:53 
Re: why cant functions return arrays
Jack Klein <jackklein@  2008-04-15 20:53:13 
Re: why cant functions return arrays
CBFalconer <cbfalconer  2008-04-16 01:09:23 
Re: why cant functions return arrays
Keith Thompson <kst@[E  2008-04-15 13:07:04 
Re: why cant functions return arrays
Shirsoft <shirsoft@[EM  2008-04-16 04:49:02 
Re: why cant functions return arrays
CBFalconer <cbfalconer  2008-04-16 09:00:08 
Re: why cant functions return arrays
"Bartc" <bc@  2008-04-16 22:56:57 
Re: why cant functions return arrays
"Default User"   2008-04-16 23:05:17 
Re: why cant functions return arrays
"Bartc" <bc@  2008-04-17 00:12:45 
Re: why cant functions return arrays
"Default User"   2008-04-17 16:18:15 
Re: why cant functions return arrays
Antoninus Twink <nospa  2008-04-16 22:00:19 
Re: why cant functions return arrays
Richard <devr_@[EMAIL   2008-04-17 18:26:04 
Re: why cant functions return arrays
"sanjay.vasudevan@[E  2008-04-18 12:15:36 
Re: why cant functions return arrays
"sanjay.vasudevan@[E  2008-04-18 12:25:20 
Re: why cant functions return arrays
Keith Thompson <kst-u@  2008-04-19 20:32:07 
Re: why cant functions return arrays
James Dow Allen <jdall  2008-04-20 04:37:22 
Re: why cant functions return arrays
jacob navia <jacob@[EM  2008-04-20 14:23:30 
Re: why cant functions return arrays
Chris Torek <nospam@[E  2008-04-20 23:45:38 
Re: why cant functions return arrays
Richard <devr_@[EMAIL   2008-04-20 13:42:00 
Re: why cant functions return arrays
Richard <devr_@[EMAIL   2008-04-20 13:44:09 
Re: why cant functions return arrays
cri@[EMAIL PROTECTED] (R  2008-04-20 16:58:08 
Re: why cant functions return arrays
Richard Heathfield <rj  2008-04-20 17:07:58 
Re: why cant functions return arrays
gazelle@[EMAIL PROTECTED]  2008-04-20 17:35:07 
Re: why cant functions return arrays
Keith Thompson <kst-u@  2008-04-20 15:07:56 
Re: why cant functions return arrays
"Default User"   2008-04-21 00:49:39 
Re: why cant functions return arrays
CBFalconer <cbfalconer  2008-04-20 18:39:27 
Re: why cant functions return arrays
Richard <devr_@[EMAIL   2008-04-20 19:46:27 
Re: why cant functions return arrays
soscpd <soscpd@[EMAIL   2008-04-20 13:28:20 
Re: why cant functions return arrays
CBFalconer <cbfalconer  2008-04-20 18:43:28 
Re: why cant functions return arrays
"Bartc" <bc@  2008-04-20 23:53:55 
Re: why cant functions return arrays
Richard <devr_@[EMAIL   2008-04-21 02:51:43 
Re: why cant functions return arrays
Richard <devr_@[EMAIL   2008-04-21 03:01:04 
Re: why cant functions return arrays
soscpd <soscpd@[EMAIL   2008-04-20 18:02:38 
Re: why cant functions return arrays
Keith Thompson <kst-u@  2008-04-20 23:25:48 
Re: why cant functions return arrays
jacob navia <jacob@[EM  2008-04-21 10:36:08 
Re: why cant functions return arrays
Nick Keighley <nick_ke  2008-04-21 01:08:37 
Re: why cant functions return arrays
Ben Bacarisse <ben.use  2008-04-21 15:21:58 
Re: why cant functions return arrays
jacob navia <jacob@[EM  2008-04-21 17:21:05 
Re: why cant functions return arrays
Ben Bacarisse <ben.use  2008-04-21 18:09:56 
Wit-to-whine ratios
James Dow Allen <jdall  2008-04-24 02:15:53 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-04-24 10:14:36 
Re: Wit-to-whine ratios
jacob navia <jacob@[EM  2008-04-24 12:36:15 
Re: Wit-to-whine ratios
pete <pfiland@[EMAIL P  2008-05-08 04:57:34 
Re: Wit-to-whine ratios
pete <pfiland@[EMAIL P  2008-05-08 05:18:48 
Re: Wit-to-whine ratios
gazelle@[EMAIL PROTECTED]  2008-05-08 12:34:27 
Re: why cant functions return arrays
John Bode <john_bode@[  2008-04-24 08:13:31 
Re: Wit-to-whine ratios
Antoninus Twink <nospa  2008-04-24 20:44:43 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-08 00:39:32 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-08 00:47:55 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-08 00:51:05 
Re: Wit-to-whine ratios
Flash Gordon <spam@[EM  2008-05-08 19:03:52 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-08 20:03:38 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-08 00:58:09 
Re: why cant functions return arrays
spinoza1111 <spinoza11  2008-05-08 04:12:50 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-08 05:50:08 
Re: Wit-to-whine ratios
Mike <m.fee@[EMAIL PRO  2008-05-12 14:00:37 
Re: Wit-to-whine ratios
CBFalconer <cbfalconer  2008-05-08 17:48:12 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-08 22:46:48 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-09 06:07:25 
Re: Wit-to-whine ratios
jacob navia <jacob@[EM  2008-05-09 09:21:55 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-09 07:50:04 
Re: Wit-to-whine ratios
jacob navia <jacob@[EM  2008-05-09 09:58:12 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-09 08:32:08 
Re: Wit-to-whine ratios
Mark McIntyre <markmci  2008-05-10 00:39:54 
Re: Wit-to-whine ratios
CBFalconer <cbfalconer  2008-05-09 23:58:02 
Re: Wit-to-whine ratios
Mark McIntyre <markmci  2008-05-10 12:06:49 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-10 04:38:49 
Re: Wit-to-whine ratios
Flash Gordon <spam@[EM  2008-05-09 18:53:39 
Re: Wit-to-whine ratios
Flash Gordon <spam@[EM  2008-05-09 18:55:58 
Re: Wit-to-whine ratios
Mark McIntyre <markmci  2008-05-10 00:48:00 
Re: Wit-to-whine ratios
Chris McDonald <chris@  2008-05-10 00:14:11 
Re: Wit-to-whine ratios
CBFalconer <cbfalconer  2008-05-10 00:01:28 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-09 18:32:09 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-10 05:03:31 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-10 10:17:24 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-10 18:12:25 
Re: Wit-to-whine ratios
Walter Banks <walter@[  2008-05-10 14:55:53 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-10 12:09:50 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-10 21:08:47 
[very OT] meds
"Malcolm McLean"  2008-05-11 21:09:26 
Re: Wit-to-whine ratios
Nick Keighley <nick_ke  2008-05-10 15:16:08 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-10 22:35:29 
Re: Wit-to-whine ratios
Richard Heathfield <rj  2008-05-11 06:57:45 
Re: Wit-to-whine ratios
pete <pfiland@[EMAIL P  2008-05-11 06:37:23 
Re: Wit-to-whine ratios
pete <pfiland@[EMAIL P  2008-05-11 08:59:08 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-10 22:38:40 
Re: Wit-to-whine ratios
James Dow Allen <jdall  2008-05-11 03:06:34 
Re: Wit-to-whine ratios
James Dow Allen <jdall  2008-05-11 03:15:58 
Re: Wit-to-whine ratios
"Default User"   2008-05-11 20:10:58 
Re: Wit-to-whine ratios
richard@[EMAIL PROTECTED]  2008-05-11 22:46:49 
Re: Wit-to-whine ratios
CBFalconer <cbfalconer  2008-05-11 07:14:49 
Re: why cant functions return arrays
spinoza1111 <spinoza11  2008-05-11 13:14:14 
Re: why cant functions return arrays
Mark McIntyre <markmci  2008-05-11 23:41:36 
Re: why cant functions return arrays
spinoza1111 <spinoza11  2008-05-11 13:18:17 
Re: why cant functions return arrays
spinoza1111 <spinoza11  2008-05-11 13:22:42 
Re: why cant functions return arrays
spinoza1111 <spinoza11  2008-05-11 13:23:53 
Re: Wit-to-whine ratios
Eligiusz Narutowicz<el  2008-05-11 22:29:00 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-11 13:40:10 
Re: Wit-to-whine ratios
Mike <m.fee@[EMAIL PRO  2008-05-12 14:21:48 
Re: Wit-to-whine ratios
pete <pfiland@[EMAIL P  2008-05-12 08:04:49 
Re: Wit-to-whine ratios
santosh <santosh.k83@[  2008-05-12 19:08:19 
Re: Wit-to-whine ratios
Colonel Sanders <colon  2008-05-13 12:54:45 
Re: why cant functions return arrays
spinoza1111 <spinoza11  2008-05-11 13:41:03 
Re: meds
spinoza1111 <spinoza11  2008-05-11 13:48:30 
Re: meds
Richard Heathfield <rj  2008-05-12 01:00:36 
Re: meds
"rio" <a@[EM  2008-05-12 11:34:34 
Re: meds
santosh <santosh.k83@[  2008-05-12 16:43:36 
Re: meds
Richard Heathfield <rj  2008-05-12 11:28:28 
[ot] s C otch
pete <pfiland@[EMAIL P  2008-05-12 07:44:15 
Re: meds
"rio" <a@[EM  2008-05-12 17:52:35 
Re: meds
santosh <santosh.k83@[  2008-05-12 21:40:36 
Re: Wit-to-whine ratios
Chad <cdalten@[EMAIL P  2008-05-11 20:40:21 
apologies to clc [Was: Wit-to-whine ratios]
Nick Keighley <nick_ke  2008-05-12 01:45:39 
Re: meds
spinoza1111 <spinoza11  2008-05-12 04:40:54 
Re: meds
Nick Keighley <nick_ke  2008-05-12 04:44:08 
Re: meds
Eligiusz Narutowicz<el  2008-05-12 13:44:43 
Re: meds
santosh <santosh.k83@[  2008-05-12 19:02:43 
Re: Wit-to-whine ratios
spinoza1111 <spinoza11  2008-05-12 04:56:53 
Re: Wit-to-whine ratios
Mike <m.fee@[EMAIL PRO  2008-05-14 10:12:44 
Re: meds
Eligiusz Narutowicz<el  2008-05-12 15:34:43 
Re: meds
santosh <santosh.k83@[  2008-05-12 19:32:30 
Re: meds
Richard Heathfield <rj  2008-05-12 14:45:30 
Re: meds
santosh <santosh.k83@[  2008-05-12 21:44:15 
Re: meds
Eligiusz Narutowicz<el  2008-05-12 16:19:06 
Re: meds
santosh <santosh.k83@[  2008-05-12 21:42:21 
Re: meds
Sri Harsha Dandibhotla &l  2008-05-12 20:57:21 
Re: meds
Richard Heathfield <rj  2008-05-13 04:05:21 
Re: meds
Sri Harsha Dandibhotla &l  2008-05-12 21:10:31 
Re: meds
Richard Heathfield <rj  2008-05-13 04:36:13 
Re: meds
Eligiusz Narutowicz<el  2008-05-13 16:32:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 21:47:51 CDT 2008.