c - 为什么在注释行后看不到初始化变量?
问题描述
错误信息是:error: 'basicInfo' undeclared (first use in this function) basicInfo->errorlog = malloc(VAL_SZ);
#include <stdio.h>
#include <stdlib.h> //malloc
#include <string.h> //strdup
#define VAL_SZ 64
typedef struct {
char* errorlog;
char* cache_size;
char* cache_replacment;
int timeout;
} basicInfo_t;
int main(int argc, char* argv[]) {
//-------------BASIC INFO SETUP-------------\\
basicInfo_t* basicInfo = malloc(sizeof(basicInfo_t));
basicInfo->errorlog = malloc(VAL_SZ);
basicInfo->cache_size = malloc(VAL_SZ);
basicInfo->cache_replacment = malloc(VAL_SZ);
return 0;
}
解决方案
在您的评论中,您\\
最后使用了 a
//-------------BASIC INFO SETUP-------------\\
告诉编译器将语句继续到下一行。因此,线
basicInfo_t* basicInfo = malloc(sizeof(basicInfo_t));
实际上对编译器不可见(=注释掉)。
删除\\
它应该可以工作。
推荐阅读
- javascript - How to fix jquery .is(':focus') not responding
- asp.net - How can I view IBM Watson Assistant conversation logs in my ASP.net application?
- javascript - 从外部的 axios 返回响应值
- java - 是否有一种方法可以在线程之间进行通信并交换信息,例如在 java 中的可运行对象中的 getter 方法
- python - 如何在不替换其他字母的情况下替换某个字母?
- php - 如何在 PHPSpreadsheet 中获取命名范围
- sql - 如果值为 NULL,则左连接,否则为内连接
- ios - “self.pushViewController”在 Swift4 中不起作用
- ibm-cloud - IBM Voice Agent RTP 端口范围
- bash - 查找 1 小时前创建的文件