struct error???

Started by
2 comments, last by Zahlman 17 years, 7 months ago
Hi, I'm having some problems with a struct definition. I'm using visual c++ express, and the code is as follows: #include "mapADT.h" #include <string.h> #include "d3dx9tex.h" #include "d3dx9.h" #include "d3d9.h" #define TRUE 1 #define FALSE 0 struct tStruct{ LPDIRECT3DSURFACE9 surface; int x_position; int y_position; long graphic; int blocked; int navigable; int mov_dif; int extra; }; typedef struct tStruct tileStruct; struct mapCDT{ char* tiles_path; long map_width; long map_hieght; int num_tiles_x; int num_tiles_y; long tile_width; long tile_hieght; LPDIRECT3DDEVICE9 d3ddev; LPDIRECT3DSURFACE9 tilesSurf; tileStruct** tileMatrix; }; tileStruct** setTileMatrix(mapADT map); LPDIRECT3DSURFACE9 getTiles(char* tile_images, LPDIRECT3DDEVICE9 d3ddev); char* getPath(const char* p); mapADT NewMap(const char* tile_images, int num_tiles_x, int num_tiles_y, long tile_width, long tile_hieght, LPDIRECT3DDEVICE9 d3ddev) { mapADT map; if ((map = malloc(sizeof(mapADT))) == NULL) return NULL; if (((char*)map->tiles_path = (char*)getPath(tile_images)) == NULL) { free(map); return NULL; } map->tile_hieght = tile_hieght; map->tile_width = tile_width; map->num_tiles_x = num_tiles_x; map->num_tiles_y = num_tiles_y; map->map_hieght = (long)num_tiles_y * tile_hieght; map->map_width = num_tiles_x * tile_width; map->d3ddev = d3ddev; map->tilesSurf = (LPDIRECT3DSURFACE9)getTiles(tile_images, d3ddev); if((map->tileMatrix = (tileStruct**)setTileMatrix(map)) == NULL) { //map->tilesSurf->Release(); free(map->tiles_path); free(map); return NULL; } return map; } // Auxiliary functions tileStruct** setTileMatrix(mapADT map) { int i, j, ok; ok = TRUE; tileStruct **ret; /****errorline****/ if((ret = malloc(sizeof(ret)* map->num_tiles_x)) == NULL) return NULL; for(i=0; i<map->num_tiles_x; i++) { if((ret= malloc(sizeof(*ret) * map->num_tiles_y)) == NULL) { ok = FALSE; break; } } if(ok == FALSE && i > 0) { while(--i) free(ret); free(ret); return NULL; } for(i=0; i<map->num_tiles_x; i++) { for(j=0; j<map->num_tiles_y; j++) { ret[j].blocked = 0; ret[j].extra = 0; ret[j].graphic = -1; ret[j].mov_dif = 10; ret[j].navigable = 0; ret[j].surface = NULL; ret[j].x_position = i; ret[j].y_position = j; } } return ret; } //the error is as follows: /* 1>.\mapADT.c(88) : error C2275: 'tileStruct' : illegal use of this type as an expression 1> .\mapADT.c(22) : see declaration of 'tileStruct' 1>.\mapADT.c(88) : error C2065: 'ret' : undeclared identifier 1>.\mapADT.c(88) : error C2100: illegal indirection */ I don't see where I'm using 'tileStruct' as an expression!!!
Advertisement
In C, all variable declarations must come at the top of a block (i.e., they must be the first things in a given scope, such as a function). You need to move
tileStruct **ret;
to come before
ok = TRUE;
Thanks!!!
0) source code goes between either [code][/code] or [source][/source] tags depending on length, please.

1) Why are you writing C code?

2) Why are you using a C++ compiler for C code?

This topic is closed to new replies.

Advertisement