#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    5
    Rep Power
    0

    Compiler error with a typdef array of a structure


    I have been trying to get a section of code to pass an array of structures to a function. I believe I have that method correct but I continue to get a compiler error which states,223) : error C2059: syntax error : ']'. The help section tells me, "If the error message occurs on a symbol immediately following a typedef'd variable, ensure that the variable has been defined somewhere in the source code. " I am not sure how to deal with this as I believe I have defined the typedef in the source file. Here is the listing of the code for my file definitions ad the calling function along with the problem line and the function.

    This is defined in my header file
    typedef struct {
    double ChordLength;
    double CumProbability;
    }TypeBoneI;

    The following is all defined in the code proper
    TypeBoneI BoneI[MAX_ARRAY];

    line 223 case BONE: ChordLength = SourceChordBone((TypeBoneI) BoneI[], RanNo);

    double SourceChordBone(TypeBoneI BoneI[], double RanNo)
    {
    double ChordLength, m, x1, x2, y1, y2, l;
    int i, j;

    i = 0;
    drand48(RanNo);

    for(i = 0; i <= MAX_ARRAY; i++)
    {
    l = BoneI[i].CumProbability;

    if(l = RanNo)
    {
    ChordLength = BoneI[i].ChordLength;
    return(ChordLength);
    break;
    }
    else
    {
    if(l > RanNo)
    {
    j = i - 1;
    y2 = BoneI[i].CumProbability;
    x2 = BoneI[i].ChordLength;
    y1 = BoneI[j].CumProbability;
    x1 = BoneI[j].ChordLength;
    m = (y2 - y1) / (x2 -x1);
    ChordLength = x2 - ((y2-y1) / m);
    return(ChordLength);
    break;
    }
    else
    {
    j = 0;
    y2 = BoneI[i].CumProbability;
    x2 = BoneI[i].ChordLength;
    y1 = 0.0;
    x1 = 0.0;
    m = (y2 - y1) / (x2 -x1);
    ChordLength = x2 - ((y2-y1) / m);
    return(ChordLength);
    break;
    }
    }
    }
    }

    If anyone sees where I am going wrong or what the solution to the above stated error message would be I would appreciate hearing form you. Thanks.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,161
    Rep Power
    2222
    You only use the empty square brackets ([]) when you declare a function, but not when you call the function. For that, the name of the array suffices:
    Code:
    typedef struct { 
    double ChordLength; 
    double CumProbability; 
    }TypeBoneI; 
    
    TypeBoneI BoneI[MAX_ARRAY]; 
    
    double SourceChordBone(TypeBoneI BoneI[], double RanNo) 
    { 
    ...
    }
    
    /* function call */
    ChordLength = SourceChordBone(BoneI, RanNo);
    There also was no need to type-cast BoneI, since it is already a TypeBoneI array name. In fact, the cast you tried would have failed, since it would have tried to turn a BoneI pointer to an actual BoneI while the function is expecting a BoneI pointer.

    Oh, did anyone ever tell you that pointers and array names are equivalent?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    5
    Rep Power
    0
    Thanks for the assit.

IMN logo majestic logo threadwatch logo seochat tools logo