|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C4700 使用了未初始化的局部变量“L” Project1 D:\Mycode\算法基础与在线实践\Project1\Project1\test02.c 58
- void InitList(SLinkNode* L) {
- L = (SLinkNode*)malloc(sizeof(SLinkNode));
- L->next = NULL;
- }
- void main() {
- int i;
- ElemType e;
- SLinkNode *L;
- InitList(L);
- InsElem(L, 1, 1);
- }
复制代码
本帖最后由 jackz007 于 2021-10-21 13:44 编辑
不是编译器问题,代码我已经修改,你可以再次尝试在 VS2019 下编译。
- #include<stdio.h>
- #include<malloc.h>
- typedef int ElemType;
- typedef struct node {
- ElemType data;
- struct node* next;
- }SLinkNode;
- void InitList(SLinkNode* L) {
- L = (SLinkNode*)malloc(sizeof(SLinkNode));
- L->next = NULL;
- }
- void DestroyList(SLinkNode *L){
- SLinkNode *pre = L, *p = pre->next;
- while(p!=NULL){
- free(pre);
- pre = p;
- p = p->next;
- }
- free(pre);
- }
- void InsElem(SLinkNode* L, ElemType x, int i) {
- int j = 0;
- SLinkNode *p = L, *s;
- if (p != NULL && j < i - 1) {
- j++;
- p = p->next;
- }
- if (p) {
- s = (SLinkNode*)malloc(sizeof(SLinkNode));
- s->data = x;
- p->next = s->next;
- p->next = s;
- }
- }
- void DispList(SLinkNode *L) {
- SLinkNode* p;
- p = L->next;
- while (p != NULL) {
- printf("%d", p->data);
- p = p->next;
- }
- printf("\n");
- }
- int main(void) {
- int i ;
- ElemType e ;
- SLinkNode * L = NULL ; // 变量一定要先初始化,然后再使用
- InitList(L) ; // 变量一定要先初始化,然后再使用
- InsElem(L, 1, 1) ;
- }
复制代码
InsElem(L, 1, 1) 函数定义的返回类型为 void,却有两个 retrn 带返回值,这在编译时会被警告,我也已经改过。
vs2019 编译实况:
- D:\00.Excise\C>cl x.c
- 用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.28.29334 版
- 版权所有(C) Microsoft Corporation。保留所有权利。
- x.c
- Microsoft (R) Incremental Linker Version 14.28.29334.0
- Copyright (C) Microsoft Corporation. All rights reserved.
- /out:x.exe
- x.obj
- D:\00.Excise\C>
复制代码
|
|