我想知道为什么整数ii在编译时初始化,但不是浮点数ff:
int main() {
const int i = 1;
constexpr int ii = i;
const float f = 1.0;
constexpr float ff = f;
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试编译时会发生的事情:
> g++ -std=c++11 test.cc
test.cc: In function ‘int main()’:
test.cc:6:24: error: the value of ‘f’ is not usable in a constant expression
constexpr float ff = f;
^
test.cc:5:15: note: ‘f’ was not declared ‘constexpr’
const float f = 1.0;
Run Code Online (Sandbox Code Playgroud) 基本上,我在默认的R绘图设备上得到了我想要的方式,希腊字母等,然后我切换绘图设备创建一个pdf文件,我有"字体"问题.
例如:
> x<- 1:4
> y<-x^2
> plot(x,y)
> text(1,2, "\u03bc") #\u03bc == 'mu'
Run Code Online (Sandbox Code Playgroud)
一切正常,根据需要在默认的R绘图设备(图形窗口)上创建希腊字母'mu'.
但是,当我然后切换绘图设备以生成.pdf文件时:
> pdf()
> plot(x,y)
> text(1,2, "\u03bc")
Run Code Online (Sandbox Code Playgroud)
给出以下内容:
Warning messages:
1: In text.default(1, 2, "?") :
conversion failure on '?' in 'mbcsToSbcs': dot substituted for <ce>
2: In text.default(1, 2, "?") :
conversion failure on '?' in 'mbcsToSbcs': dot substituted for <bc>
3: In text.default(1, 2, "?") :
font metrics unknown for Unicode character U+03bc
4: In text.default(1, 2, "?") :
conversion failure …Run Code Online (Sandbox Code Playgroud) man 7 mq_overviewPOSIX 表示“...系统上的消息队列可以使用通常用于文件的命令(例如 ls(1) 和 rm(1))来查看和操作。” 例如,我能够使用 mqd_t 作为文件描述符进行读取,如下所示:
#include <iostream>
#include <fcntl.h>
#include <mqueue.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "Usage: mqgetinfo </mq_name>\n";
exit(1);
}
mqd_t mqd = mq_open(argv[1], O_RDONLY);
struct mq_attr attr;
mq_getattr(mqd, &attr);
std::cout << argv[1] << " attributes:"
<< "\nflag: " << attr.mq_flags
<< "\nMax # of msgs: " << attr.mq_maxmsg
<< "\nMax msg size: " << attr.mq_msgsize
<< "\nmsgs now in queue: …Run Code Online (Sandbox Code Playgroud) 在C++中,
double x = 1.0;
double y = x / 3.0;
if (x == y * 3.0)
cout << " They are equal!" ;
else
cout << " They are NOT equal." ;
Run Code Online (Sandbox Code Playgroud)
将打印
‘They are NOT equal.’
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,由于1/3的非精确表示为(二进制)数量的有限大小的尾数.但是在Python中(在https://repl.it/repls/MessyJaggedMouse上),
x = 1.0
y = x / 3.0
x == y * 3.0
Run Code Online (Sandbox Code Playgroud)
版画
True
Run Code Online (Sandbox Code Playgroud)
何时以及为什么Python会偏离上述预期的行为?编辑:Python不会离开 - 请参阅下面的答案.
该程序位于名为localFunc.c的文件中:
#include <stdio.h>
// int f(int); // Global forward declaration.
int main() {
int f(int); // Local forward declaration.
printf("%d\n", f(1));
}
double f(int i) {
return 1.0;
}
Run Code Online (Sandbox Code Playgroud)
编译via gcc localFunc.c给出:
localFunc.c:10:8: error: conflicting types for ‘f’
double f(int i) {
^
localFunc.c:6:7: note: previous declaration of ‘f’ was here
int f(int); // Local forward declaration.
Run Code Online (Sandbox Code Playgroud)
但编译通过g++ localFunc.c,没有错误,运行可执行文件的结果是:4195638.
评论本地前向声明,并启用全局前向声明:int f(int);,gcc和g ++都会出现类似于上面的错误,正如预期的那样(由我).
所以我的问题是,为什么看起来g ++没有在本地声明的函数上看到冲突类型(模糊声明)?
don@HAL:~/UNIX/CS213$ gcc --version
gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
Run Code Online (Sandbox Code Playgroud)