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


Groups > comp.lang.c > #15062

Re: rms from rosettacode

From 88888 Dihedral <dihedral88888@googlemail.com>
Newsgroups comp.lang.c
Subject Re: rms from rosettacode
Date 2011-12-27 15:54 -0800
Organization http://groups.google.com
Message-ID <25602645.400.1325030053011.JavaMail.geo-discussion-forums@prdv33> (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於 2011年12月28日星期三UTC+8上午2時33分51秒寫道:
> BartC ha scritto:
> > "superpollo" <superpollo@tznvy.pbz> wrote in message 
> > news:4ef99d34$0$1379$4fafbaef@reader2.news.tin.it...
> >> http://rosettacode.org/wiki/Averages/Root_mean_square#C
> > 
> >> #include <stdio.h>
> >> #include <math.h>
> >>
> >> double rms(double *v)
> >> {
> >>     const int n = sizeof(v) / sizeof(double);
> >>     int i;
> >>     double sum = 0.0;
> >>     for (i = 0; i < n; i++)
> >>         sum += v[i] * v[i];
> >>     return sqrt(sum / n);
> >> }
> > 
> >> [~/superpollo]$ cc -lm rms.c && ./a.out
> >> nan
> > 
> >> what gives?
> > 
> > Try printing the value of n. You'll probably find it's zero. Your 
> > for-loop while keep going for quite a while, since it starts at i=0, and 
> > won't stop until i<0, perhaps two billion iterations later, by which 
> > time you will have long since breached the array bounds.
> > 
> > (BTW size(v) is just the number of bytes in a pointer. The array size 
> > must be made known explicity. Or you can use rand() to just guess the 
> > size; it will probably get it right more often than your code!)
> 
> so, to summarize: it is not possible for a function that gets an array 
> passed to figure by herself the size, right? so the *idiomatic* way to 
> give that info to the funtion should be that of the original rosettacode 
> code, or is there another way?
> 
> bye
> 
> -- 
> Chissa' perche' in un triangolo (5*5)/2=12.5
> ci stanno 125 triangolini ???

This does matter in the pass by register implementations of calling 
a function. The rule of thumb in IA32 X86 is that 3 32bit parameters 
to be the input parameters of a function is OK by __fastcall. 


But for MIPS compatible CPUs, things are not the same. 

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