Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #15033

Re: rms from rosettacode

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.c
Subject Re: rms from rosettacode
Date 2011-12-27 19:04 +0000
Organization Freie Universitaet Berlin
Message-ID <9luj5mFv0tU1@mid.uni-berlin.de> (permalink)
References <4ef99d34$0$1379$4fafbaef@reader2.news.tin.it> <jdd1v3$7ka$1@dont-email.me> <4efa0f91$0$1375$4fafbaef@reader2.news.tin.it>

Show all headers | View raw


superpollo <superpollo@tznvy.pbz> wrote:
> so, to summarize: it is not possible for a function that gets an array 
> passed to figure by herself the size, right?

Correct. And that's because you can't pass an array to a function,
that's simply not possible in C. All you can pass to a function is
a pointer to an element (typically the first) of an array (when you
call a function with an array as an argument the array is silently
converted to such a pointer to its first element). And with just
knowing the address of the first element of the array the function
can't determine the length of the array, thus you have to pass it
separately. Or, as it already has been pointed out, you could use
a sentinel element to mark the end of the array - but that re-
quires that a value existst that never can be a valid data value
of your array.

The only real way around that would be to wrap the array into
a structure - structures (in contrast to arrays) can be passed
to functions. But, of course, there's a downside: when you pass
around a structure a complete copy of the structure must be cre-
ated which can be rather time- and memory-consuming.

                                Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 11:25 +0100
  Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 06:48 -0500
    Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 13:01 +0100
      Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 07:10 -0500
        Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 13:36 +0100
          Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 10:04 -0500
    Re: rms from rosettacode Keith Thompson <kst-u@mib.org> - 2011-12-27 14:42 -0800
      Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 18:46 -0500
  Re: rms from rosettacode 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 09:49 -0800
  Re: rms from rosettacode "BartC" <bc@freeuk.com> - 2011-12-27 18:14 +0000
    Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 19:33 +0100
      Re: rms from rosettacode jt@toerring.de (Jens Thoms Toerring) - 2011-12-27 19:04 +0000
        Re: rms from rosettacode Keith Thompson <kst-u@mib.org> - 2011-12-27 14:45 -0800
        Re: rms from rosettacode blp@cs.stanford.edu (Ben Pfaff) - 2011-12-27 14:57 -0800
      Re: rms from rosettacode "BartC" <bc@freeuk.com> - 2011-12-27 19:06 +0000
        Re: rms from rosettacode Bull in a China Blue Shop <chine.bleu@yahoo.com> - 2011-12-27 16:16 -0800
      Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 14:11 -0500
      Re: rms from rosettacode Seebs <usenet-nospam@seebs.net> - 2011-12-27 20:13 +0000
      Re: rms from rosettacode Johann Klammer <klammerr@NOSPAM.aon.at> - 2011-12-28 00:23 +0100
      Re: rms from rosettacode 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 15:54 -0800
        Re: rms from rosettacode Keith Thompson <kst-u@mib.org> - 2011-12-27 22:53 -0800
          Re: rms from rosettacode Seebs <usenet-nospam@seebs.net> - 2011-12-28 06:29 +0000
          Re: rms from rosettacode 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-28 02:45 -0800
  Re: rms from rosettacode Kaz Kylheku <kaz@kylheku.com> - 2011-12-27 19:53 +0000
    Re: rms from rosettacode Seebs <usenet-nospam@seebs.net> - 2011-12-27 20:13 +0000
    Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 21:31 +0100
      Re: rms from rosettacode Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-27 20:49 -0500
        Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-28 11:42 +0100
          Re: rms from rosettacode Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-29 08:18 -0800
        Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-28 11:54 +0100
          Re: rms from rosettacode Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-12-29 04:12 +0200
            Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-29 14:38 +0100
        Re: rms from rosettacode Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-28 02:26 -0800
          Re: rms from rosettacode Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-28 21:35 -0500
            Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-29 14:10 +0100
        Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-28 08:03 -0500
          Re: rms from rosettacode "BartC" <bc@freeuk.com> - 2011-12-28 13:32 +0000
            Re: rms from rosettacode Dr Nick <3-nospam@temporary-address.org.uk> - 2011-12-28 13:41 +0000
            Re: rms from rosettacode Kaz Kylheku <kaz@kylheku.com> - 2011-12-28 19:29 +0000
            Re: rms from rosettacode Keith Thompson <kst-u@mib.org> - 2011-12-28 13:47 -0800
            Re: rms from rosettacode Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-12-29 04:19 +0200
      Re: rms from rosettacode Kaz Kylheku <kaz@kylheku.com> - 2011-12-28 19:11 +0000

csiph-web