1

I get the error:

C2275 RHandle: illegal use of this type as an expression

...when I compile this:

int main(){
    int i,j;
    float** tree;
    tree = (float**)malloc(15 * sizeof(float*));
    for( i = 0; i < 15; i++) 
        tree[i] = (float*)malloc(2 * sizeof(float));
    for(i = 0; i < 15; i++)
        for( j = 0; j < 2; j++)
            tree[i][j] = 2;

    RHandle h = create_reprVectorsTree(tree, 8, 2); // error at this line
    // ...
}

My interface looks like this:

struct reprVectorsTree;

#ifdef __cplusplus
extern "C" {
#endif

typedef struct reprVectorsTree * RHandle;
RHandle create_reprVectorsTree(float **, int , int );
void free_reprVectorsTree(RHandle);
float*  work_decode(RHandle , int *, int);

#ifdef __cplusplus
}
#endif

I followed the example from this question.

I am compiling on Visual Studio 2008.

What is the problem?

Community
  • 1
  • 1
  • How is `tree` defined? Your function takes `float**` as first argument, is that OK? – Kiril Kirov Aug 16 '12 at 18:39
  • This compiles fine for me (GCC 4.6.3) – James M Aug 16 '12 at 18:42
  • I am using VS2008 :(, should I do something different so that it ll work with visual studio? –  Aug 16 '12 at 18:42
  • @user494461 Ah, see my answer. If you want your current code to compile you'll need to either compile it as C++ or just use a modern C compiler (i.e. not MSVC). – James M Aug 16 '12 at 18:52

2 Answers2

3

Just a guess, but if this is being compiled as C89 you can't have a variable declared in the middle of the scope like that.

int main(){
int i,j;
float** tree;
RHandle h;
tree = (float**)malloc(15 * sizeof(float*));
for( i = 0; i < 15; i++) 
    tree[i] = (float*)malloc(2 * sizeof(float));
for(i = 0; i < 15; i++)
    for( j = 0; j < 2; j++)
        tree[i][j] = 2;    
h = create_reprVectorsTree(tree, 8, 2);
James M
  • 18,506
  • 3
  • 48
  • 56
0

Did you start your code with

#include "my_header.h"

using, of course, whatever name your interface file has? As written, the compiler doesn't have any way to know what RHandle means.

Please don't summarize code. The mistakes are often in the parts that you "know* are right, and leave out of the summary.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165