问题标签 [memset]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
104 浏览

c++ - 你能解释一下输出并指出错误吗

此 printf 的输出为空白,即“framerequest ::”。谁能指出我做错了什么?

在 gcc 4.1.2 中编译

0 投票
4 回答
371 浏览

c - -1 是一个有效的指针地址吗

可能重复:
指针(地址)可以是负数吗?

我正在考虑使用 memset 将结构初始化为所有 -1(因为它不使用带符号的数字并且零是有效值)。

-1 是有效的指针地址吗?我的想法还有其他问题吗?注意:平台是 linux/gcc/x86

PS我正在尝试初始化一个不是所有指针的结构,其中零对所有无效的类似值都有效,因此我可以选择在一个函数中进行部分初始化,然后将未初始化的字段初始化为默认值。如果在 c 中有一个模式/策略可以做到这一点?

0 投票
5 回答
2399 浏览

c++ - 为什么 memset() 放在循环体内时不能正常工作?

昨天我用 C++ 编写了一小段代码,其中包含一个循环和一个数组。在程序中,每次循环重新开始时,我都需要重置数组。但是,如果我使用

然后数组不会被重置为全0。对于这个程序,我使用:

反而。

但是,我认为循环不如函数清晰,它需要一个额外的变量,更不用说这比 memset() 函数的魔法要酷一百万倍。各位大神能不能给我解惑一下?

0 投票
3 回答
10777 浏览

c - memset 的替代品

我想初始化一个结构数组,但是 memset() 的第二个参数需要一个 int。是否还有另一个功能相同但带有 (void *) 的函数具有第二个参数?我想到了 memcpy() 但它没有在整个数组中设置值。任何的想法?

结构:

编码:

0 投票
3 回答
8038 浏览

c - 为什么 memset 采用 int 而不是 char?

为什么memset将 aint作为第二个参数而不是 a char,而wmemset将 a而不是orwchar_t之类的东西?longlong long

0 投票
4 回答
5521 浏览

c - memset 用于内存分配?

我在 msdn 上看这个例子:

http://msdn.microsoft.com/en-us/library/ms894209.aspx

似乎他们使用 memset 作为向 mbiMemory 分配内存的一种方式。可以吗?我不会这样跑过一些内存吗?谢谢!

0 投票
2 回答
1051 浏览

c - malloc 后的 memset

我有一个 linux 产品的三行(版本)。V1 在客户中运行良好。V2 和 V3 崩溃,修复似乎是 malloc 调用后的 memset 调用。

关于这个话题的更深层次的解释是什么?为什么 memset 解决了这个问题?

0 投票
5 回答
469 浏览

c++ - How can i set same int value to an array of ints

I have a variable:

I want to set same int to all array values. I can't use memset because it works with bytes.

How can i do that?

0 投票
1 回答
573 浏览

xcode - memset on a statically-allocated zlib Byte array in a library crashes an Objective-C++ program

I'm writing a library that uses a statically-allocated C-array of type Byte, defined in zlib.h. I'm finding that the code crashes on a call to memset. The complete code looks like this:

I tried pre-computing the value of kLabelBufSiz * sizeof(Byte) and using the numeric value for the memset, but it made no difference. This is a single-threaded program and there is no code between the two calls, so I know that the memory and pointer are not changing. I confirmed that sizeof(Byte) is 1. I tried changing the array type to char, and that stopped the crash, so it seems that the Byte type may be playing a role here.

I wrote a smaller program that calls this library function, and that one does not crash. The non-crashing program is pure C++, whereas the crashing one is Objective-C++. I'm building them both on Mac OSX 10.6.7, with gcc-4.2 and XCode. Is there something about ObjC++ that could cause problems here? I've never had problems with C++ libraries called from ObjC++ before, but that doesn't mean they don't exist. Any help is greatly appreciated!

0 投票
3 回答
27269 浏览

c - c语言中的memset函数

我现在正在研究 memset 函数,但所有示例都与 char 数组有关,如下所示:

它将这个 char 数组中的每个元素设置为 0。

我想知道 memset 是否可以应用于 int 数组或 float 数组?