在 Xcode 6.1 中获取预期的标识符或“(”问题
Getting a Expected identifier or '(' issue in Xcode 6.1
我是 C 的新手。我试过其他链接但没有成功。
我正在使用 Xcode 6.1,但遇到以下问题:
解析问题:预期标识符或'('
语义问题:意外的类型名称 'map'
这是我的代码:
//hashmap.h
#ifndef __HashMap__hashmap__
#define __HashMap__hashmap__
void map_init();
void map_insert(uint8_t, uint8_t);
uint8_t map_getVal(uint8_t);
#endif /* defined(__HashMap__hashmap__) */
//hashmap.c
#include <stdint.h>
#include "hashmap.h"
#define KEY_NOT_FOUND -1
static int i = 0;
typedef struct HashMap {
uint8_t KEY;
uint8_t VAL;
} *map;
void map_init() {
map = (HashMap*) calloc(1, sizeof(HashMap)); //Parse Issue
}
void map_insert(uint8_t key, uint8_t val) {
int size;
map[i].KEY = key; //Parse Issue
map[i].VAL = val; //Parse Issue
i++;
size = i + 1;
map = (HashMap*) realloc(map, size * sizeof(HashMap)); //Parse Issue
}
int map_search(HashMap map[], uint8_t key) {
int index, size = i;
for(index = 0; index <= size; index++)
if(map[index].KEY == key)
return index;
return KEY_NOT_FOUND;
}
uint8_t map_getVal(uint8_t key) {
return map[map_search(map, key)].VAL; //Semantic Issue
}
我尝试用指针数组符号 (map + i) 替换 map[i] 产生相同的结果。也请随时指出问题解决后我的 hashmap 将如何失败。
类型定义:
typedef struct HashMap {
uint8_t KEY;
uint8_t VAL;
} *mapEntry;
定义了一个名为 *mapEntry
的新 类型 。然后您可以创建一个实际变量:
mapEntry map;
现在,您的代码的其余部分应该是可解析的,因为 map
指的是变量而不是类型。
变化:
typedef struct HashMap {
uint8_t KEY;
uint8_t VAL;
} *map;
与:
typedef struct HashMap {
uint8_t KEY;
uint8_t VAL;
} HashMap ;
HashMap *map;
我是 C 的新手。我试过其他链接但没有成功。
我正在使用 Xcode 6.1,但遇到以下问题:
解析问题:预期标识符或'('
语义问题:意外的类型名称 'map'
这是我的代码:
//hashmap.h
#ifndef __HashMap__hashmap__
#define __HashMap__hashmap__
void map_init();
void map_insert(uint8_t, uint8_t);
uint8_t map_getVal(uint8_t);
#endif /* defined(__HashMap__hashmap__) */
//hashmap.c
#include <stdint.h>
#include "hashmap.h"
#define KEY_NOT_FOUND -1
static int i = 0;
typedef struct HashMap {
uint8_t KEY;
uint8_t VAL;
} *map;
void map_init() {
map = (HashMap*) calloc(1, sizeof(HashMap)); //Parse Issue
}
void map_insert(uint8_t key, uint8_t val) {
int size;
map[i].KEY = key; //Parse Issue
map[i].VAL = val; //Parse Issue
i++;
size = i + 1;
map = (HashMap*) realloc(map, size * sizeof(HashMap)); //Parse Issue
}
int map_search(HashMap map[], uint8_t key) {
int index, size = i;
for(index = 0; index <= size; index++)
if(map[index].KEY == key)
return index;
return KEY_NOT_FOUND;
}
uint8_t map_getVal(uint8_t key) {
return map[map_search(map, key)].VAL; //Semantic Issue
}
我尝试用指针数组符号 (map + i) 替换 map[i] 产生相同的结果。也请随时指出问题解决后我的 hashmap 将如何失败。
类型定义:
typedef struct HashMap {
uint8_t KEY;
uint8_t VAL;
} *mapEntry;
定义了一个名为 *mapEntry
的新 类型 。然后您可以创建一个实际变量:
mapEntry map;
现在,您的代码的其余部分应该是可解析的,因为 map
指的是变量而不是类型。
变化:
typedef struct HashMap {
uint8_t KEY;
uint8_t VAL;
} *map;
与:
typedef struct HashMap {
uint8_t KEY;
uint8_t VAL;
} HashMap ;
HashMap *map;