c++ - 如何解决long int * 转换成volatile int *类型的编译错误.
PHP中文网
PHP中文网 2017-04-17 15:32:37
0
2
652
PHP中文网
PHP中文网

认证0级讲师

reply all(2)
PHPzhong

No error will be reported in C, but there will be a warning:

>>> gcc -o a a.c
a.c: 在函数‘main’中:
a.c:8:7: 警告:从不兼容的指针类型赋值 [-Wincompatible-pointer-types]
     a = b;
       ^
a.c:5:19: 警告:变量‘a’被设定但未被使用 [-Wunused-but-set-variable]
     volatile int *a = NULL;
                   ^
>>> cp a.c a.cpp
>>> g++ -o a a.cpp
a.cpp: 在函数‘int main()’中:
a.cpp:8:9: 错误:不能在赋值时将‘long int*’转换为‘volatile int*’
     a = b;
         ^

The reason for the warning is clear, int and long are incompatible. An error will be reported in C++ because C++'s type system is more strict.

Please label the question correctly to avoid attracting non-professional people and wasting both parties’ time.

PHPzhong

has nothing to do with volatile. int and long themselves are of different types (can have different lengths). Of course you will get an error if you pass it off like this. First check whether there is any problem with the logic of your code, and then use type conversion with caution.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!