Thread: error: initializer expression list treated as compound expression

  1. #1
    Registered User
    Join Date
    Nov 2009

    Question error: initializer expression list treated as compound expression

    Hi all,
    i would like to say thank you for this forum to provide many facility for us.

    i have code in c++ with gsl library to calculate the regression. but i can not run it there is error says:
    initializer expression list treated as compound expression
    and i do not know how to avoid it.....please guys i need your help.
    the code is:
    #include <iostream>
    #include <stdio.h>
    #include <gsl/gsl_multifit.h>
    #include <gsl/gsl_matrix.h>
    #include <gsl/gsl_vector.h>
    using namespace std;

    double reg(int n, int p, double *mo, double *pg, double *l, double *ll)
    double store[p];
    gsl_multifit_linear_workspace *ws;
    gsl_matrix *cov, *X;
    gsl_vector *y, *c;
    double chisq;
    int i, j;
    X = gsl_matrix_alloc(n, p);
    y = gsl_vector_alloc(n);
    c = gsl_vector_alloc(p);
    cov = gsl_matrix_alloc(p, p);
    for(i=0; i < n; i++)
    gsl_matrix_set(X, i, 0, 1.0);
    gsl_matrix_set(X, i, 1, mo[i]);
    gsl_matrix_set(X, i, 2, pg[i]);
    gsl_matrix_set(X, i, 3, l[i]);
    gsl_vector_set(y, i, ll[i]);
    ws = gsl_multifit_linear_alloc(n, p);
    gsl_multifit_linear(X, y, c, cov, &chisq, ws);
    /* store result ... */
    for(i=0; i < p; i++)
    store[i] = gsl_vector_get(c, i);
    return *store; /* we do not "analyse" the result (cov matrix mainly)
    to know if the fit is "good" */

    int main ()
    int pixel = 4, parameter=4;
    gsl_vector* st;
    st = gsl_vector_alloc (parameter);
    gsl_vector_free (st);
    double modis[]={4.31, 3.83, 3.13, 3.51};
    double pg3[]={2.5, 3.94, 3.63, 2.08};
    double prel[]={2.50, 4.39, 4.09, 2.95};
    double nexl[]={3.4,3.8,3.3,2.7};
    reg(pixel, parameter, *modis, *pg3, *prel, *nexl);
    return 0;

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    First, indent your code.
    Second, you never actually call reg. Remove the "double" to do a function call.
    As for the error, it's because you try to create an array with a non-constant variable as the size parameter. This is illegal in C++.

    int n= 10;
    int arr[n]; // Illegal

    const int n = 10;
    int arr[n]; // OK
    int arr[10]; // OK

    You can use std::vector instead:

    int n = 10;
    std::vector arr(n); // OK
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2009
    thank you very much for your replay

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 03:58 PM
  2. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 02:29 AM
  3. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  4. 1st Class LIST ADT
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 07:29 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM
Website Security Test