有很多和*_v后缀*_t,例如std::is_same_v、std::invoke_result_t和数result_of_t以百万计的其他此类函数。
它们为什么存在?std::result_of::type在任何情况下公开诸如或 之类的实现细节是否有益std::is_same::value?忽略标准合规性,_v _t版本是否应该始终是首选?难道这些::type ::value版本根本就不存在吗?
用gcc8编译:
#include <stdio.h>
void some_func(void f1(void), void (*f2)(void))
{
printf("%d\n", f1);
printf("%d\n", f2);
}
Run Code Online (Sandbox Code Playgroud)
给(仅)以下警告:
<source>:11:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'void (*)(void)' [-Wformat=]
printf("%d\n", f1);
<source>:12:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'void (*)(void)' [-Wformat=]
printf("%d\n", f2);
Run Code Online (Sandbox Code Playgroud)
为什么类型f1相同f2?仅f2被声明为函数指针.我希望f1不会编译,因为它命名一个函数类型,而不是函数指针.什么规则说,函数参数列表中的函数类型更改为指向该函数类型的指针?
在阅读 glibc 源代码时,我偶然发现了assert.h中的这条评论:
/* The following is not at all used here but needed for standard
compliance. */
extern void __assert (const char *__assertion, const char *__file, int __line)
__THROW __attribute__ ((__noreturn__));
Run Code Online (Sandbox Code Playgroud)
什么标准规定了__assert函数?
我在 POSIX 或 C 或 git 提交历史记录中找不到任何内容,也无法在网络或本网站上找到任何内容。
我认为在重新分配动态分配的指针时,我们都理解删除的必要性,以防止内存泄漏.但是,我很好奇,C++在多大程度上强制要求使用delete?例如,采取以下计划
int main()
{
int* arr = new int[5];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
虽然所有意图和目的都没有发生泄漏(因为你的程序结束了,操作系统会在它返回后清理所有内存),但标准是否还需要 - 或建议 - 在这种情况下使用delete [] ?如果没有,还有其他原因你会在这里删除[]吗?
我正在尝试将 ip 地址存储到外部字符串中。我的 ip 地址值在 .cpp 中,但后来我想将它存储在我的 .h 文件中。我将它存储为字符串,因为我想将其作为链接。(http://"ip 地址"/)
我的 .h 文件
extern std::string ipadd1 = "";
Run Code Online (Sandbox Code Playgroud)
我的 .cpp 文件
if (connectWifi("", "") == WL_CONNECTED) {
DEBUG_WM(F("IP Address:"));
DEBUG_WM(WiFi.localIP());
ipadd1 = String(WiFi.localIP());
//connected
return true;
}
Run Code Online (Sandbox Code Playgroud) 我有一个这样的示例input.txt文件:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
Run Code Online (Sandbox Code Playgroud)
现在,我可以轻松地grep输入一个单词,并获取它的字节偏移量:
$ grep -ob incididunt /dev/null input.txt
input.txt:80:incididunt …Run Code Online (Sandbox Code Playgroud) 我有一组 CentOS 7 机器,我之前安装了“docker”;然而,我发现有一个针对 CentOS 的较新版本的存储库,其中添加了 docker 存储库:“docker-ce”。
Name : docker
Arch : x86_64
Epoch : 2
Version : 1.12.6
Release : 68.gitec8512b.el7.centos
Size : 15 M
Repo : extras/7/x86_64
versus
Name : docker-ce
Arch : x86_64
Version : 17.12.0.ce
Release : 1.el7.centos
Size : 123 M
Repo : installed
From repo : docker-ce-stable
Run Code Online (Sandbox Code Playgroud)
哪个版本是首选运行版本?越新越好,还是 CentOS 附加功能附带的软件包最好?那么操作系统供应商还是软件供应商?
static const int a = 42;
static const int b = a;
Run Code Online (Sandbox Code Playgroud)
我希望在这样的代码中出现编译错误.初始值设定项必须是常量表达式或字符串文字.存储在int具有const类型限定符类型的对象中的值不是常量表达式.
我编译-Wall -Wextra -pedantic,甚至与-ansi.然后:
error: initializer element is not constant令人惊讶的是,以下内容:
static const char * const a = "a";
static const char * const b = a;
Run Code Online (Sandbox Code Playgroud)
error: initializer element is not constanterror: initializer element is …我有以下代码:
int add_ii(int a, int b) { return a + b; }
unsigned add_iu(int a, unsigned b) { return a + b; }
unsigned add_ui(unsigned a, int b) { return a + b; }
unsigned add_uu(unsigned a, unsigned b) { return a + b; }
#define add(LEFT, RIGHT) \
_Generic(LEFT \
,int: _Generic(RIGHT \
,int: add_ii \
,unsigned: add_iu \
) \
,unsigned: _Generic(RIGHT \
,int: add_ui \
,unsigned: add_uu \
) \
)(LEFT, RIGHT)
int main() {
return add(1, …Run Code Online (Sandbox Code Playgroud)