我知道标题似乎很愚蠢,但我认为值得一提.
以此声明(或定义,可能)为例:
_Thread_local long volatile static int _Atomic const long unsigned x = 10;
Run Code Online (Sandbox Code Playgroud)
我以前认为long long是一种类型,但如果它是一个类型名称,那么如何插入这么多限定符呢?
所以我用这个问题咨询了N1570,只是更加困惑.它提到了一些术语,如" type-specifier "和" type-qualifier ",我long long在"类型说明符"中找不到,但long long在C中不是原始类型?有这么多书告诉我了!
澄清不重复:
是的,我看到了存在的问题与交易long int long,但这个问题有什么做预选赛,并且是C.
也许我生锈了(最近用Python编写).
为什么这不编译?
if ( (int i=f()) == 0)
Run Code Online (Sandbox Code Playgroud)
没有我()周围的int i=f()另一个,更合理的错误i是不是布尔.但这就是为什么我首先想要括号!
我的猜测是使用括号使其成为表达式,并且表达式中不允许使用声明语句.是这样吗?如果是的话,它是C++的语法怪癖之一吗?
顺便说一下,我实际上是想这样做:
if ( (Mymap::iterator it = m.find(name)) != m.end())
return it->second;
Run Code Online (Sandbox Code Playgroud) 最近,我发现有些情况绝对会违反C++的ODR,但在C编译器中会编译好.
例如,这个奇怪的场景(和我一起):
来源1
int var_global=-3;
Run Code Online (Sandbox Code Playgroud)
来源2
#include <stdio.h>
#include <conio.h>
unsigned int var_global;
int main() {
printf("%d \n",var_global);
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我有打印结果-3(即使在源2 var_global中unsigned)并且没有关于重新定义的错误var_global.
我知道C与C++有不同的规则,但我认为它不是那么不同.
我有谷歌并阅读了很多结果,但没有像 C++ 这样的官方结果.
所以问题是:
C有像C++这样的一个定义规则吗?
和:
什么叫官方?
我需要它与C++规则进行比较,这样我才能更深入地理解这两种语言.
p/s:我使用Visual Studio 2010编译上面的代码.
考虑这个代码:
void foo()
{
goto bar;
int x = 0;
bar: ;
}
Run Code Online (Sandbox Code Playgroud)
GCC 和 Clang拒绝它,因为跳转到bar:绕过变量初始化。MSVC 根本不抱怨(除非使用xafterbar:导致警告)。
我们可以用 a 做类似的事情switch:
void foo()
{
switch (0)
{
int x = 0;
case 0: ;
}
}
Run Code Online (Sandbox Code Playgroud)
现在所有三个编译器都发出错误。
这些片段格式不正确吗?或者他们会导致UB?
我曾经认为两者都是格式错误的,但我找不到标准的相关部分。[stmt.goto]不说这事,而且也不[stmt.select] 。
我在C文件中定义了一个变量:int x我知道extern int x如果我想在其他文件中使用它,我应该用它来在其他文件中声明它.
我的问题是:我应该在其他文件中将其声明在哪里?
在所有功能之外,
// in file a.c:
int x;
// in file b.c:
extern int x;
void foo() { printf("%d\n", x); }
Run Code Online (Sandbox Code Playgroud)在将使用它的功能内?
// in file b.c:
void foo() {
extern int x;
printf("%d\n", x);
}
Run Code Online (Sandbox Code Playgroud)我的怀疑是:
我开始工作几周了,而且(再一次)我偶然发现了一些对我来说很奇怪的事情:
// Not working
a := 1
{
a, b := 2, 3
}
// Works
a := 1
a, b := 2, 3
Run Code Online (Sandbox Code Playgroud)
我想同时分配两个变量.一个已经宣布,在一个优越的范围,另一个不是.
它不起作用:编译器尝试重新声明前一个变量.但是,如果在同一范围内声明此变量,则它可以正常工作.
这是为什么 ?
我有编译GNUARM编译器的代码,但Visual Studio 2010发出错误.该问题涉及在C语言文件中的第一个语句之后声明变量:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i = 6;
i = i + 1;
printf("Value of i is: %d\n", i);
int j = i * 10; // <-- This is what Visual Studio 2010 complains about.
printf("Value of j is: %d\n", j);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
以下代码编译时没有错误:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i = 6;
int j; // <-- Declaration is now here, valid according to K&R rules.
i = i + …Run Code Online (Sandbox Code Playgroud) 我不明白的意思typedef void interrupt_handler();.有人可以用一些例子解释一下吗?
typedef void interrupt_handler();
Run Code Online (Sandbox Code Playgroud) 我查看了大量的教程,手册和文档,但我仍然无法使用它.
我正在尝试使用phpMyAdmin创建存储过程.
我似乎无法在这里找到错误,sql错误是如此模糊......
CREATE PROCEDURE insertToonOneShot(IN locale CHAR(2), IN name VARCHAR(16), IN realm VARCHAR(24), IN faction CHAR(1), IN toon_level INT, IN class_name INT)
BEGIN
DECLARE @realmID INT;
DECLARE @classID INT;
DECLARE @toonID INT;
SET @realmID = SELECT id FROM realms WHERE realms.name = realm;
SET @classID = SELECT id FROM classes WHERE classes.name = class_name;
IF NOT @realmID IS NULL AND NOT @classID IS NULL AND @toonID IS NULL THEN
INSERT INTO
toon (`locale`, `name`, `realm_id`, `faction`, `level`, `class_id`)
VALUES …Run Code Online (Sandbox Code Playgroud) c ×5
c++ ×4
declaration ×2
syntax ×2
expression ×1
extern ×1
go ×1
goto ×1
initializer ×1
mysql ×1
sql ×1
typedef ×1