initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

../src/yongqiang.c:29:15: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

1. Node *head = root;

//============================================================================
// Name        : typedef - struct
// Author      : Yongqiang Cheng
// Version     : Version 1.0.0
// Copyright   : Copyright (c) 2019 Yongqiang Cheng
// Description : Hello World in C++, Ansi-style
//============================================================================/*** Insert into an ordered, singly linked list. The arguments are** a pointer to the first node in the list, and the value to insert.*/#include <stdio.h>
#include <stdlib.h>#define    FALSE   1
#define TRUE    0typedef struct NODE
{struct NODE *link;int value;
} Node;// This function prints contents of linked list starting from the given node.
int sll_display(const Node *root)
{Node *head = root;if (NULL == root){return FALSE;}printf("\n[ ");while (NULL != head){printf("%d ", head->value);head = head->link;}printf("]");return TRUE;
}int sll_insert(Node **rootp, int new_value)
{Node *current;Node *previous;Node *new_node;if (NULL == rootp){return FALSE;}/*** Get the pointer to the first node.*/current = *rootp;previous = NULL;/*** Look for the right place by walking down the list** until we reach a node whose value is greater than or equal to the new value.*/while ((NULL != current) && (current->value < new_value)){previous = current;current = current->link;}/*** Allocate a new node and store the new value into it.** In this event, we return FALSE.*/new_node = (Node *) malloc(sizeof(Node));if (NULL == new_node){return FALSE;}new_node->value = new_value;/*** Insert the new node into the list, and return TRUE.*/new_node->link = current;if (NULL == previous){*rootp = new_node;}else{previous->link = new_node;}return TRUE;
}int main()
{Node *root = NULL;int result = 0;int ret = 0;ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 5);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 10);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 15);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 9);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 12);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 0);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 20);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}return TRUE;
}
16:47:30 **** Build of configuration Debug for project yongqiang_example ****
make all
Building file: ../src/yongqiang.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/yongqiang.d" -MT"src/yongqiang.o" -o "src/yongqiang.o" "../src/yongqiang.c"
../src/yongqiang.c: In function ‘sll_display’:
../src/yongqiang.c:29:15: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]Node *head = root;^
Finished building: ../src/yongqiang.cBuilding target: yongqiang_example
Invoking: GCC C Linker
gcc  -o "yongqiang_example"  ./src/yongqiang.o
Finished building target: yongqiang_example16:47:31 Build Finished (took 595ms)
NULL pointer.
[ 5 ]
[ 5 10 ]
[ 5 10 15 ]
[ 5 9 10 15 ]
[ 5 9 10 12 15 ]
[ 0 5 9 10 12 15 ]
[ 0 5 9 10 12 15 20 ]

2. const Node *head = root;

//============================================================================
// Name        : typedef - struct
// Author      : Yongqiang Cheng
// Version     : Version 1.0.0
// Copyright   : Copyright (c) 2019 Yongqiang Cheng
// Description : Hello World in C++, Ansi-style
//============================================================================/*** Insert into an ordered, singly linked list. The arguments are** a pointer to the first node in the list, and the value to insert.*/#include <stdio.h>
#include <stdlib.h>#define    FALSE   1
#define TRUE    0typedef struct NODE
{struct NODE *link;int value;
} Node;// This function prints contents of linked list starting from the given node.
int sll_display(const Node *root)
{const Node *head = root;if (NULL == root){return FALSE;}printf("\n[ ");while (NULL != head){printf("%d ", head->value);head = head->link;}printf("]");return TRUE;
}int sll_insert(Node **rootp, int new_value)
{Node *current;Node *previous;Node *new_node;if (NULL == rootp){return FALSE;}/*** Get the pointer to the first node.*/current = *rootp;previous = NULL;/*** Look for the right place by walking down the list** until we reach a node whose value is greater than or equal to the new value.*/while ((NULL != current) && (current->value < new_value)){previous = current;current = current->link;}/*** Allocate a new node and store the new value into it.** In this event, we return FALSE.*/new_node = (Node *) malloc(sizeof(Node));if (NULL == new_node){return FALSE;}new_node->value = new_value;/*** Insert the new node into the list, and return TRUE.*/new_node->link = current;if (NULL == previous){*rootp = new_node;}else{previous->link = new_node;}return TRUE;
}int main()
{Node *root = NULL;int result = 0;int ret = 0;ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 5);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 10);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 15);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 9);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 12);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 0);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}result = sll_insert(&root, 20);if (result){printf("Failed to insert element.");}ret = sll_display(root);if (ret){printf("NULL pointer.");}return TRUE;
}
16:44:22 **** Build of configuration Debug for project yongqiang_example ****
make all
Building file: ../src/yongqiang.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/yongqiang.d" -MT"src/yongqiang.o" -o "src/yongqiang.o" "../src/yongqiang.c"
Finished building: ../src/yongqiang.cBuilding target: yongqiang_example
Invoking: GCC C Linker
gcc  -o "yongqiang_example"  ./src/yongqiang.o
Finished building target: yongqiang_example16:44:23 Build Finished (took 602ms)
NULL pointer.
[ 5 ]
[ 5 10 ]
[ 5 10 15 ]
[ 5 9 10 15 ]
[ 5 9 10 12 15 ]
[ 0 5 9 10 12 15 ]
[ 0 5 9 10 12 15 20 ]

initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]相关推荐

  1. 2020-10-26runtime error: member access within null pointer of type ‘struct ListNode‘ (solution.cpp)错

    runtime error: member access within null pointer of type 'struct ListNode' (solution.cpp)错误 /*** Def ...

  2. CCS5.5 中报错 Does not match the target type,not loaded 的一种情况

    出现现象:在使用CCS5.5调试TMS320DM642时,代码没有任何报错,却出现不能导入出数情况,报错信息是Does not match the target type,not loaded.用的是 ...

  3. Line 923: Char 9: runtime error: reference binding to null pointer of type ‘int‘ (stl_vector.h)

    Leetcode 报错 Line 923: Char 9: runtime error: reference binding to null pointer of type 'int' (stl_ve ...

  4. leetcode报错runtime error: reference binding to null pointer of type ‘std::vector<std::__cxx11::basic_

    leetcode报错:runtime error: reference binding to null pointer of type 'std::vector<std::__cxx11::ba ...

  5. Mybatis异常--java.lang.IllegalArgumentException: NO ENUM const class org.apache.ibatis.type.JdbcType.i

    转载:http://www.cnblogs.com/jl29233zx/p/6226522.html Mybatis异常--java.lang.IllegalArgumentException: NO ...

  6. mybatis No enum const class org.apache.ibatis.type.JdbcType.Date 坑爹的配置

    转自:https://lihaiming.iteye.com/blog/2248059 在ibatis中不需要关注这些参数 而转到mybatis后 如果字段值为空 必须设置jdbcType 如 ins ...

  7. leetcode报错:member access within null pointer of type struct ListNode

    leetcode报错:member access within null pointer of type 'struct ListNode'

  8. LeetCode报错:Line 923: Char 9: runtime error: reference binding to null pointer of type ‘std::__cxx11:

    LeetCode报错 报错原因: Line 923: Char 9: runtime error: reference binding to null pointer of type 'std::__ ...

  9. 力扣报错runtime error: load of null pointer of type ‘int‘解决思路

    记录本算法小白刷力扣的这道题遇到的报错 349. 两个数组的交集https://leetcode.cn/problems/intersection-of-two-arrays/ 出现报错的代码 /** ...

  10. 【Leetcode记录】runtime error: member access within null pointer of type ‘ListNode‘ (solution.cpp) SUMMA

    环形链表快慢指针: runtime error: member access within null pointer of type 'ListNode' (solution.cpp) SUMMARY ...

最新文章

  1. 秒抢红包的背后,是复杂的即时付款系统
  2. WebGL 浏览器函数
  3. 决策树算法介绍及应用
  4. python生成器yield_python 生成器yield的总结
  5. Caused by: java
  6. 连接mysql数据库2013_使用VS2013 + EF6 + .NET4.5 连接Mysql数据库
  7. 性能测试、 障碍条件和回滚
  8. 用JAVA实现数字水印(可见)
  9. mysql 怎么改属性_mysql怎么修改字段的属性
  10. redhat rhel 7中如何切换中英文输入法。
  11. 数据结构和算法基础(6)——常用十种算法
  12. Windows下载安装kafka
  13. CSS盒模型居中方法,看这篇足矣了!
  14. 【BZOJ5285】【HNOI2018】寻宝游戏
  15. 园区人工智能开启双创模式,“1+N”创新型组织发展成效初显...
  16. 害怕字体侵权?可以免费商用的字体库来了!
  17. 【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
  18. STM32使用MDK keil 调试问题汇总
  19. Qt 编译报错 error: invalid use of incomplete type 'class QXxx'
  20. 如何通过WWW下载图片 学习笔记

热门文章

  1. t检验临界值表中的n是什么_t检验临界值表
  2. 圆柱体积怎么算立方公式_圆柱的立方计算公式
  3. 整体大于部分_整体叶盘球头鼓锥形铣刀五轴加工技术
  4. Power BI集成Power Apps,轻松实现用户在报告中任意输入信息
  5. 前嗅教你大数据——史上最全代理IP服务商对比
  6. 守望先锋-生涯数据信息抓取的实现
  7. 使用技巧-输出彩色TIF格式分类结果
  8. 机器学习(十)——支持向量机
  9. 硬件只要一块esp8266 nodemcu板+几根杜邦线实现远程PC开机,软件全开源(替代智能开关)
  10. js 异步 回调函数