Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编译某些旧C++;软件(格式应为int类型,参数为int32) 我想编译一些可以使用的C++软件。是2001年的。运行make就可以了_C++_G++_Format_Int_Scanf - Fatal编程技术网

编译某些旧C++;软件(格式应为int类型,参数为int32) 我想编译一些可以使用的C++软件。是2001年的。运行make就可以了

编译某些旧C++;软件(格式应为int类型,参数为int32) 我想编译一些可以使用的C++软件。是2001年的。运行make就可以了,c++,g++,format,int,scanf,C++,G++,Format,Int,Scanf,我使用的是Ubuntu10.10,我必须将makefile中的gcc更改为g++,才能进行编译 警告: 现在,程序需要扫描一个参数文件。编译时,我会收到几个警告: g++ -c -o packet_data_agent.o packet_data_agent.cpp packet_data_agent.cpp: In constructor ‘PACKET_DATA_AGENT::PACKET_DATA_AGENT()’: packet_data_agent.cpp:34: warning

我使用的是Ubuntu10.10,我必须将makefile中的
gcc
更改为
g++
,才能进行编译

警告: 现在,程序需要扫描一个参数文件。编译时,我会收到几个警告:

g++    -c -o packet_data_agent.o packet_data_agent.cpp
packet_data_agent.cpp: In constructor ‘PACKET_DATA_AGENT::PACKET_DATA_AGENT()’:
packet_data_agent.cpp:34: warning: deprecated conversion from string constant to ‘char*’
packet_data_agent.cpp: In member function ‘void PACKET_DATA_AGENT::initialize(FILE*, FILE*)’:
packet_data_agent.cpp:109: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:128: warning: format ‘%d’ expects type ‘int*’, but argument 3 has type ‘int32*’
packet_data_agent.cpp:131: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:136: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:141: warning: format ‘%d’ expects type ‘int*’, but argument 3 has type ‘int32*’
packet_data_agent.cpp:144: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:149: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp: In member function ‘int32 PACKET_DATA_AGENT::get_PDU(int32, VIRTUAL_PDU*)’:
packet_data_agent.cpp:213: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:244: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp: In member function ‘void PACKET_DATA_AGENT::put_PDU(int32, VIRTUAL_PDU*)’:
packet_data_agent.cpp:312: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp: In member function ‘void PACKET_DATA_AGENT::write_statistics(FILE*)’:
packet_data_agent.cpp:393: warning: format ‘%10d’ expects type ‘int’, but argument 3 has type ‘int32’
packet_data_agent.cpp:394: warning: format ‘%10d’ expects type ‘int’, but argument 3 has type ‘int32’
g++ -O4  mobile_ip.o loss_generator.o radio_link_agent.o packet_data_agent.o -o mobile_ip -lm
我的问题是: 这些导致我无法解析包含的设置文件。在
packet\u data\u agent.h
中,变量声明为
int32

int32 compressed_Internet_header_size;
< >和C++代码扫描参数文件>代码包PATETYDATAXActudio.CPP:128 :

fscanf(ParameterFile_ptr,"- compressed RTP/UDP/IP header size (in bytes): %d\n",&compressed_Internet_header_size);
但当我运行程序时,我收到以下错误:

!!error in module PACKET-DATA-AGENT: illegal value 0 for the compressed RTP/UDP/IP header size
尽管参数文件显然有:

- compressed RTP/UDP/IP header size (in bytes): 3
如何使程序正确解析参数文件

其他信息:
  • 我的平台上
    int
    的大小为4
以下是我的g++版本:

$ g++ -v
Using built-in specs.
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) 
一些非常简单的调试: 我对源代码做了如下更改:

int return_test = fscanf(ParameterFile_ptr,"- compressed RTP/UDP/IP header size (in bytes): %d\n",&compressed_Internet_header_size);
printf ("%d\n", return_test);
printf ("%d\n", compressed_Internet_header_size);

输出为0,0。这意味着什么?我是说,说真的,它就在我面前,找不到参数?

警告:

标题
global.h
使
int32
成为
long
的同义词。当您使用格式代码
%d
long
传递到
*printf
时,gcc会发出警告,因为在某些平台上(任何
int
为32位且
long
为64位的平台,或
int
为16位且
long
为32位的平台),将产生非常糟糕的结果

您可以更改typedef,使
int32
表示
int
,而不是
long
,这样可能不会发生什么坏事

运行时的实际错误

[根据原始提问者提供的新信息编辑:]

这似乎与
int
/
long
/
int32
内容无关:相反,
fscanf
无法读取参数文件的那一行。那之前的线路呢?
fscanf
是否为它们全部返回1,或者它实际上是以一种不会使其停止解析文件的方式在前面出错


假设所有早期的
fscanf
调用都成功了,这是第一个失败的调用:如果将源代码中的固定样板文件复制并粘贴到文件中会发生什么?如果你让它只寻找一个没有固定模板文本的数字呢?参数文件中包含输出RTP流的
文件
行和
压缩RTP/UDP/IP头大小
行之间没有任何其他行,是吗


您可以通过以下方式了解它失败的地方:在有问题的
fscanf
调用之后,使用
fread
读取一点参数文件,显示它,然后退出(当然,没有必要继续;如果这样做,解析器将完全混乱)。例如,如果由于遇到与
fscanf
格式字符串中的常量文本不匹配的字符而失败,则应给出不匹配的字符和以下内容。如果它失败是因为它试图读取一个整数,但看到了它不喜欢的东西,那么您应该得到它无法解释为整数的一部分的第一个字符以及下面的一些字符。等。

为了便于移植,您应该使用以下格式的字符串宏:


在那个平台上,
int
的大小是多少?好吧,我的答案应该是代码预期编译为32位,而您编译的是64位,但g++-v建议不是这样。int32应该是int的typedef,所以看到这个警告很奇怪。我想这是一个线索,我只是不知道是什么!一种愚蠢的方法是使用
printf(“d\n”,sizeof(int))
main()
@sharptooth的开头附近,我把它添加到了上面的问题中。谢谢。对于4字节
int
,这是我无法解释的。我应该养成在键入答案之前刷新页面的习惯:pI相应地更改了源代码,fscanf返回0,参数读取显然也是0。“在参数文件中,..和…行之间没有任何其他行,是吗?”没有-有一个根本没有被解析!我发誓,如果我见过这个软件的开发者…是的,这是一个。。。有趣的。。。解析配置文件的方式:-)。
int32_t myint;
... = scanf("%" SCNi32, %myint);