I have a simple program to run the Romberg algorithm however when I tried to compile it, it keeps returning that
error: conflicting types for 'vector' and
error: conflicting types for 'free_vector'
I really cannot see why this is happening. Would you be able to advice?

#include <stdio.h> 
#include <stdlib.h> 
#include <math.h> 
#include "nrutil.h" 
 
#define FUNC(x) ((*func)(x)) 
#define EPS 1.0e-6 
#define JMAX 20 
#define JMAXP (JMAX+1) 
#define K 5 
 
#define FT_TYPE double 
#define FT_OUT "%10.20g" 
 
void nrerror(char error_text[]); 
FT_TYPE *vector(long nl, long nh);  
void free_vector(FT_TYPE *v, long nl, long nh); 

FT_TYPE qromb(FT_TYPE (*func)(FT_TYPE), FT_TYPE a, FT_TYPE b);
FT_TYPE trapzd(FT_TYPE (*func)(FT_TYPE), FT_TYPE a, FT_TYPE b, int n);
void polint(FT_TYPE xa[], FT_TYPE ya[], int n, FT_TYPE x, FT_TYPE *y, FT_TYPE *dy);

FT_TYPE INTEGRAND(FT_TYPE x);

int main(int argc, char *argv[]){ 
 
  //int n = 10; 
  //int i; 
 
  printf("The first function is F(x) = exp(x)\n"); 
  qromb(INTEGRAND, 0.0, 2.0);     
 
  return(0); 
} 
 
 
FT_TYPE INTEGRAND(FT_TYPE x){ 
  return(exp(x)); 
} 
 
 
 
 
 
#define NR_END 1 
#define FREE_ARG char* 
 
 
FT_TYPE *vector(long nl, long nh)  
/*  allocate a FT_TYPE vector with subscript range v[nl..nh] */  
{  
        FT_TYPE *v;  
  
        v=(FT_TYPE *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(FT_TYPE)));  
        if (!v) nrerror("allocation failure in vector()");  
        return v-nl+NR_END;  
}  
 
 
void free_vector(FT_TYPE *v, long nl, long nh)  
/*  free a FT_TYPE vector allocated with vector() */  
{  
        free((FREE_ARG) (v+nl-NR_END));  
} 
 
 
void nrerror(char error_text[]) 
/*  Numerical Recipes standard error handler */ 
{ 
        fprintf(stderr,"Numerical Recipes run-time error...\n"); 
        fprintf(stderr,"%s\n",error_text); 
        fprintf(stderr,"...now exiting to system...\n"); 
        exit(1); 
}

Following by the standard codes of qromb, etc from Numerical Recipes in C.

The program doesn't have problem on other functions but only the FT_TYPE *vector and void free_vector function.

Would you be able to advice why would this happen?

Recommended Answers

All 2 Replies

Vector is a C collection class . Do you really require the names of your functions to be vector and free_vector ?

I compiled it with VC++ 2010 Express and got no such warnings or errors. Are you sure you are compiling this as C program instead of C++. With vc++2010 *.cpp files are compiled as c++, not C. Change the file extension to *.c and recompile.

>>Vector is a C collection class .
Correction: its C++, not C.

[edit]Just tried to compile as c++ and didn't get the error then either. Of course I don't have the header file nrutil.h, so the problem might be a conflict in that file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.