🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #52269

problem with pointer to function

#52269
From: Wolfgang Walter
Date: Tue, 08 Dec 1992 15:59
46 lines
1859 bytes
If I compile it with another C-compiler, it works.
It works also, if I call f in Int directly. Nobody could tell me, why.
So, if anyone had a Idea what is wrong with it, I would be very glad.
I work with a hp 700, gcc version 2.3.2 .
I compiled it with     gcc Int.c -lm .


Here's the program :

/* kleines C-Programm fuer Stephan, der C lernt */

#include <stdio.h>
#include <math.h>  /* falls exp, sin, ... erwuenscht */

double f(double x)
{ return x*x;      /* zum einfachen Testen */
}

double Int(double (*f)(double),double a, double b, int n)
{ double h, w, s = 0.0;
  int i;
  h = (b-a)/n;
  printf("h: %f\n",h);
  for(i=0;i<n;i++)
     { w = (*f)(a+i*h);
       s += w*h;
       printf("Schritt %d, w: %f, s: %f\n",i,w,s);
     };
  return s;
}

int main(void)
{ double a,b,Erg;
  int n;
  printf("Bitte a eingeben: ");
  scanf("%lf",&a);
  printf("Bitte b eingeben: ");
  scanf("%lf",&b);
  printf("Bitte die Anzahl der Schritte eingeben: ");
  scanf("%d",&n);
  printf("f(0): %f\n",f(0.0));
  Erg = Int(&f,a,b,n);
  printf("Ergebnis ist : Int(%f,%f) = %f\n",a,b,Erg);
  return 0;
}
Technical Details
Message-ID: <1992Dec8.155939.24207@Informatik.TU-Muenchen.DE>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!mailgzrz.TU-Berlin.DE!math.fu-berlin.de!informatik.tu-muenchen.de!walterw

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,1b0773f100d367ea,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1992-12-08 08:42:24 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!mailgzrz.TU-Berlin.DE!math.fu-berlin.de!informatik.tu-muenchen.de!walterw
From: walterw@Informatik.TU-Muenchen.DE (Wolfgang Walter)
Subject: problem with pointer to function
Originator: walterw@hphalle6a.informatik.tu-muenchen.de
Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
Organization: Technische Universitaet Muenchen, Germany
Date: Tue, 8 Dec 1992 15:59:39 GMT
Message-ID: <1992Dec8.155939.24207@Informatik.TU-Muenchen.DE>
Lines: 46