问题标签 [c99]

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 投票
4 回答
1542 浏览

c - C(不是 C++)的异常库

我正在为 C 滚动我自己的异常库,并希望有很好的例子来检查。

到目前为止,我一直在看大卫汉森的: http ://drhanson.net/work/

但我知道我过去见过其他可用的。你能给我一些额外的指示吗?

谢谢,

SetJmp

0 投票
3 回答
3122 浏览

c - 当我将 std=c99 标志添加到 gcc 时,fileno、F_LOCK 和 F_ULOCK 变得未声明且不可用

我在 ac 代码中有这些标题

在我将 -std=c99 标志添加到 gcc 命令(以启用restrict)之前,一切都编译得很好。这触发了以下错误。

警告:函数的隐式声明fileno

错误:F_LOCK未声明(在此函数中首次使用)
错误:(每个未声明的标识符仅报告一次错误:对于它出现的每个函数。)
错误:F_ULOCK未声明(在此函数中首次使用)

解决这些错误/警告的任何想法?

0 投票
3 回答
2673 浏览

c - 关于指向指针的指针,C99 的“限制”的语义是什么?

我正在做很多矩阵运算,并希望利用 C99 的restrict指针限定符。

我想将我的矩阵设置为指向指针的指针,以便于下标,如下所示:

现在,对于矩阵乘法函数

我必须将参数的两个指针都限定为受限吗?这是有效的语法,但我很难确定int *restrict *restrict其行为是否与int **restrict.

那么,在正确限制指针的情况下,是否通过A[0][col*nrows + row]undefined 访问元素?(即,编译器是否会假设我通过这样A[col][row]的值访问矩阵)?还是我必须保持一致?rowrow < nrow

0 投票
6 回答
77509 浏览

c++ - UINT32_MAX 的 C++ 等价物是什么?

在 C99 中,我包含stdint.h和,这给了我UINT32_MAX以及uint32_t数据类型。但是,在 C++ 中UINT32_MAX定义了。我可以在 include__STDC_LIMIT_MACROS之前定义stdint.h,但如果有人在包含他们自己之后包含我的标题,这将不起作用stdint.h

那么在 C++ 中,找出 a 中可表示的最大值的标准方法是uint32_t什么?

0 投票
3 回答
6374 浏览

c - C 中的暂定定义和链接

考虑由两个文件组成的 C 程序,

f1.c:

f2.c:

我对 C99 标准第 6.9.2 段的解读是,这个程序应该被拒绝。在我对 6.9.2 的解释中,变量x在 中暂定定义f1.c,但这个暂定定义在翻译单元的末尾变成了实际定义,因此(在我看来)应该表现得好像f1.c包含定义一样int x=0;

对于我能够尝试的所有编译器(以及重要的链接器),这不是发生的事情。我尝试的所有编译平台都链接上述两个文件,两个文件中的值x都是2。

我怀疑这是偶然发生的,或者只是作为标准要求之外提供的“简单”功能。如果您考虑一下,这意味着链接器对那些没有初始化程序的全局变量有特殊支持,而不是那些显式初始化为零的变量。有人告诉我,无论如何编译 Fortran 都可能需要链接器功能。这将是一个合理的解释。

对此有什么想法吗?标准的其他解释?哪些平台的文件名f1.cf2.c拒绝链接在一起?

注意:这很重要,因为问题发生在静态分析的上下文中。如果这两个文件可能拒绝在某个平台上链接,分析器应该抱怨,但如果每个编译平台都接受它,那么没有理由警告它。

0 投票
6 回答
2558 浏览

c - What can human beings make out of the restrict qualifier?

If I got the C99 restrict keyword right, qualifying a pointer with it is a promise made that the data it references won't be modified behind the compiler's back through aliasing.

By contrast, the way I understand the const qualifier is as compiler-enforced documentation that a given object won't be modified behind the back of a human being writing code. The compiler might get a hint as a side effect, but as a programmer I don't really care.

In a similar way, would it be appropriate to consider a restrict qualifier in a function prototype as a requirement that the user ensures exclusive access ("avoid aliasing", or maybe something stronger) for the duration of the call? Should it be used as "documentation"?

Also, is there something to understand in the fact that restrict qualifies a pointer rather than the data it points to (as const does) ?

EDIT: I originally believed that restrict could have implications with threaded code, but this seems wrong so I remove references to threads from the question to avoid confusing readers.

0 投票
6 回答
29937 浏览

c - C 预处理器是否首先剥离注释或扩展宏?

考虑一下这个(可怕的,糟糕的,不好的,非常糟糕的)代码结构:

我已经看到两个编译器的预处理器在这段代码上产生了不同的结果:

显然,这对于可移植的代码库来说是一件坏事。

我的问题:预处理器应该对此做什么?先删除注释,还是先展开宏?

0 投票
1 回答
506 浏览

c - How to auto-sync Header in Visual Studio?

Do you know if there is a build-in feature or free add-in for Microsoft Visual Studio 2008 that easily generates C-Headers and keeps them in sync with their .c counterparts? I have already looked at Visual Assist X, but I'm not really willing to pay money at the moment.

0 投票
3 回答
2002 浏览

c - scanf 不超过缓冲区溢出

我有一个缓冲区,我不希望用户输入的字符多于缓冲区可以容纳的字符(以避免缓冲区溢出)。

我正在使用scanf并且已经这样做了:

但是,我知道如果用户输入超过 30 个,我会受到保护。但是,如果用户输入超过 30 个,缓冲区是否会以空值终止?

0 投票
3 回答
271 浏览

c - How to declare IEEE mathematical functions like 'ilogbf' in MSVC++6?

Could someone please help and tell me how to include IEEE mathematical functions in MSVC++6? I tried both and , but I still get these errors:

error C2065: 'ilogbf' : undeclared identifier

error C2065: 'scalbnf' : undeclared identifier