草庐IT

Wzero-as-null-pointer-constant

全部标签

c++ - 为什么 rand() 在此 for 循环中使用 srand(time(null)) 返回相同的值?

我有以下代码#include#include"time.h"usingnamespacestd;voidprintRandomNumber(){srand(time(NULL));cout输出是相同的数字重复六次,我希望它打印出混合数字。 最佳答案 因为您每次都使用相同的值播种-time只有秒级精度,而且我很确定您的计算机可以在一秒钟内处理这六个循环迭代。;-]种子一次,在程序的开头。 关于c++-为什么rand()在此for循环中使用srand(time(null))返回相同的值?,我

c++ - 如何摆脱 - 来自 NULL 的 "warning: converting to non-pointer type ' 字符”?

我有这段代码:intmyFunc(std::string&value){charbuffer[fileSize];....buffer[bytesRead]=NULL;value=buffer;return0;}行-buffer[bytes]=NULL给我一个警告:convertingtonon-pointertype'char'fromNULL。我如何摆脱这个警告? 最佳答案 不要使用NULL?它一般是为指针保留的,你没有指针,只有一个简单的char。只需使用\0(空终止符)或简单的0。

c++ - 在 C/C++ 中编写 "pointer to something"的好方法

在C/C++中是否有一种“好的”方式来编写“指向某物的指针”?我曾经写过voidfoo(char*str);但有时我发现它很不合逻辑,因为str的类型是“指向char的指针”,那么它应该更合乎逻辑将*附加到类型名称。写指针有规律吗?char*str;char*str;char*str;char*str; 最佳答案 没有严格的规则,但请记住*附加到变量,所以:char*str1,*str2;//str1andstr2arepointerschar*str1,str2;//str1isapointer,str2isachar有些人也喜欢

c++ - ORA-24347 : Warning of a NULL column in an aggregate function

我收到这个警告:ORA-24347:WarningofaNULLcolumninanaggregatefunction在生产中使用Oracle的MAX()函数时。我正在使用OCI库连接到Oracle,版本11.2.0.2。但是,在测试服务器上,这个错误并没有出现。我对查询进行了硬编码,以便可以将NULL值传递给聚合函数。我仍然无法重现此问题。此警告是否与任何Oracle错误相关?谁能提供一些会引发此警告的示例查询?编辑:Table:EX_TABLEColumns:IDNOT NULLNUMBERSOME_NUMBERNUMBERMAX_VALNUMBER查询:selectMAX(DEC

c++ - 如何正确地将 _bstr_t 重置为 `NULL`

在下面的代码片段中(循环的简化场景)_bstr_toriginal(OLESTR("MyString"));//ref-count=1_bstr_tanother;another=original;//ref-count=2//dosomethingwithanotheranother.Assign(NULL);//expected:ref-count=1,andanother=NULL//resetanothertoNULLbeforedoingotheroperations在another.Assign(NULL)之后我期望的是:SysFreeString()未被调用另一个设置为N

c++ - 函数返回 auto 自动参数 munmap_chunk() : invalid pointer

我正在测试newfeature对于GCC4.9(自动输入参数)并出现一些奇怪的错误。#include#includeautofoo(autov){for(auto&&i:v)std::cout{1,2,3});}这给我以下错误:***glibcdetected***./a.out:munmap_chunk():invalidpointer:0x00007f87f58c6dc0***=======Backtrace:=========/lib/x86_64-linux-gnu/libc.so.6(+0x7e846)[0x7f87f4e4c846]./a.out[0x400803]/lib

c++ - 为什么将 "pointer to pointer to non-const"转换为 "pointer to pointer to const"是不合法的

将非const指针转换为const指针是合法的。那为什么将指向非const的指针转换为指向const的指针是不合法的呢?例如,为什么下面的代码是非法的:char*s1=0;constchar*s2=s1;//OK...char*a[MAX];//akachar**constchar**ps=a;//error! 最佳答案 来自标准:constcharc='c';char*pc;constchar**pcc=&pc;//notallowed*pcc=&c;*pc='C';//wouldallowtomodifyaconstobject

NULL条件操作员是否返回False,如果为空?

我有这个条件if(item?.Value2?.GetType()!=typeof(string)&&item.get_Value()==0)我相信如果项目为无效?.操作将返回null,我认为该操作将被解决为false导致条件短路,一切都会很好(item.get_Value()不会被称为)但是我不确定,我想也许我需要这样做if(item?.Value2?.GetType()??0!=typeof(string)&&item.get_Value()==0)但是我认为这可能是过度的,这是第一种免受潜在零参考例外的方法吗?看答案item?.Value2?.GetType()将返回null如果item是

c++ - 使用 stxxl 队列时为 `pointer being freed was not allocated`

我的代码似乎可以工作(由于上述错误,我还没有在大型数据集上尝试过)。代码:#include#include#includeintmain(){//queueq;//thisworksstxxl::queueq;//doesnotworkfor(inti=0;i我的简单.stxxl就是:disk=./testfile,0,syscall但我的错误是:stackexchangeexample(3884)malloc:***errorforobject0x101c04000:pointerbeingfreedwasnotallocated***setabreakpointinmalloc_e

c++ - FFmpeg 库 : Exactly constant segment duration for HLS

我们正在使用FFmpeg库git-ee94362libavformatv55.2.100。我们的目的是使用HLS将两个流(视频和音频)混合到M3U8播放列表中。此外,我们希望每个TS片段文件的持续时间正好为3.0秒(帧速率为25fps)。为了实现它,我们尝试设置几个选项和属性,即:-分段时间-keyint_min-scenechange_threshold-gop_size-force_key_frames。我们的代码如下所示:AVCodecContext*codec_ctx=NULL;AVFormatContext*ofmt_ctx=NULL;intret=0,gopSize=(in