小编Ant*_*hov的帖子

C++ 中格式错误的 goto 跳转,编译时已知为假条件:它实际上是非法的吗?

我正在学习 C++ 的一些黑暗角落,特别是关于“禁止”goto及其使用的一些限制。这个问题的部分灵感来自Patrice Roy 在 CppCon 2019 “Some Programming Myths Revisited”上的演讲链接到具有类似示例的确切时间)。

请注意,这是一个语言律师问题,我绝不提倡goto在此特定示例中使用 。


以下 C++ 代码:

#include <iostream>
#include <cstdlib>

struct X {
    X() { std::cout<<"X Constructor\n"; }
    ~X() { std::cout<<"X Destructor\n"; }
};

bool maybe_skip() { return std::rand()%10 != 0; }

int main()
{
    if (maybe_skip()) goto here;
    
    X x; // has non-trivial constructor; thus, preventing jumping over itself
    here:
    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

格式错误,无法编译。因为goto可以跳过具有非平凡构造函数x的类型的初始化X

来自 …

c++ goto language-lawyer

41
推荐指数
1
解决办法
2555
查看次数

VM428:7 未捕获类型错误:无法在 &lt;anonymous&gt;:7:17 处读取 null 属性(读取“CodeMirror”)

代码运行良好,但我不明白在哪里收到此错误:

VM428:7 Uncaught TypeError: Cannot read properties of null (reading 'CodeMirror')
    at <anonymous>:7:17
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

16
推荐指数
2
解决办法
1万
查看次数

为什么在使用静态方法时取消引用 nullptr 而不是 C++ 中的未定义行为?

我正在阅读一篇关于nullptrC++ 中一些特性的文章,一个特定的例子在我的理解中引起了一些混乱。

考虑(来自上述帖子的简化示例):

struct A {   
    void non_static_mem_fn() {}  
    static void static_mem_fn() {}  
};


A* p{nullptr};

/*1*/ *p;
/*6*/ p->non_static_mem_fn();
/*7*/ p->static_mem_fn();
Run Code Online (Sandbox Code Playgroud)

根据作者的说法/*1*/,取消引用 the 的表达式nullptr本身不会导致未定义的行为。与/*7*/使用nullptr-object 调用静态函数的表达式相同。

理由基于C++ Standard Core Language Closed Issues, Revision 100中的issue 315

... *pis not an error when pis null 除非左值被转换为右值(7.1 [conv.lval]),它不在这里。

从而区分/*6*//*7*/

因此,对实际的间接引用nullptr 不是未定义行为在SO答案在C ++标准的问题232讨论,...)。因此,/*1*/在这个假设下, 的有效性是可以理解的。

但是,如何 …

c++ static-methods null-pointer undefined-behavior language-lawyer

9
推荐指数
1
解决办法
298
查看次数

C ++标准中带有`restrict`关键字/属性的情况

In short, restrict is supposed to tell the compiler that the pointers cannot point into the same memory location. Which is very useful for, say, function arguments and further compiler optimization. In scientific computing, restrict is very widely used.

Currently, restrict keyword is only a part of C99, but not a part of C++. We know that a lot of C++ compilers support __restrict__ as an extension. This question also talks in detail about what restrict and __restrict__ do.

Now, …

c++ standards restrict-qualifier c++20

7
推荐指数
1
解决办法
237
查看次数

关闭异步 resteasy 客户端调用的最佳方法

我有以下代码:

var threadsWaiter = new CountDownLatch(customers.size());
for(var c: List<Customer> customers) {
   sendSms(c.phoneNr, threadsWaiter)
}
threadsWaiter.await();

public void sendSms(String phoneNr, CountDownLatch threadsWaiter) {
  ResteasyClientBuilder.newClient()
            .target(smsUrl)                
            .queryParam("to", phoneNr)
            .queryParam("message", message)
            .request()
            .async()
            .get(new InvocationCallback<String>() {
                @Override
                public void completed(String res) {
                    threadsWaiter.countDown();
                    if (res != null && !res.contains("code=ok") {
                        logger.error("Received sms response for '{}'\n{}", phoneNr, res);
                    } else {                            
                        logger.debug("Sms sent to '{}'", phoneNr);
                    }
                }

                @Override
                public void failed(Throwable throwable) {
                    threadsWaiter.countDown();
                    logger.error("Error sending sms for {}: \n{}", phoneNr, throwable.getMessage());
                } …
Run Code Online (Sandbox Code Playgroud)

resteasy quarkus

6
推荐指数
1
解决办法
1348
查看次数

如何防止 clang-format 缩进从第 0 列开始的注释?

我希望 clang-format 不缩进或更改从行首开始的所有注释。

原因是,在 Eclipse 中,我可以通过输入ctrl+来注释和取消注释/一行,但如果注释完后按 clang-format 缩进,然后取消注释,则最终缩进是错误的。

关于如何做到这一点有什么想法吗?

clang-format

6
推荐指数
0
解决办法
477
查看次数

如何在 Airflow 中的电子邮件操作员上附加文件

每当我将文件参数添加到email_task我的运行失败时。

email_task = EmailOperator(    
           task_id='email_sample_data',    
           to='sample@sample.com',    
           subject='Forecast for the day',    
           html_content= "Sample",
           files=['/home/airflow/sample.html'],    
           dag=dag)
Run Code Online (Sandbox Code Playgroud)

我收到一个错误,提示找不到文件。气流在哪里选择我的文件,我需要在哪里上传文件,“文件”参数的正确语法是什么?

airflow airflow-operator

6
推荐指数
1
解决办法
93
查看次数

ZigBee Mesh VS DigiMesh

ZigBee Mesh(系列 2)和 DigiMesh(系列 1)哪个更好?

我已经阅读了无线网状网络,ZigBee 与 DigiMesh(PDF 格式),但我注意到使用 DigiMesh 有很多优点,相反,我希望阅读系列 2 比系列 1 更好。

zigbee xbee mesh-network

5
推荐指数
1
解决办法
9568
查看次数

使用batman-adv协议在Raspberry Pi上进行无线网状网络连接

第一次海报,所以如果我做错了什么,我道歉!

所以我正在尝试使用Raspberry Pi设置无线网状网络,使用Edimax EW-7811Un WLAN适配器和batman-adv协议.

我尝试过以下基本设置指南:
http://www.open-mesh.org/projects/batman-adv/wiki/Quick-start-guide
http://mindofdes.blogspot.co.uk/2013/ 02 /覆盆子-PI-raspbian-无线and.html

不幸的是,当我到达需要从另一个节点ping一个节点时,我得到
'目标主机无法访问'.

运行'batctl o'命令显示'范围内没有蝙蝠侠节点',但是当运行'iwconfig'时,两个节点似乎都与我设置的网络相关联,当运行'iwlist wlan0 scan'时,网络我'设置在两个节点上显示为单元格.

我现在不知道如何继续.我已经阅读了一些关于linux wlan适配器驱动程序的临时支持问题的文章.我的适配器正在使用RTL8192CU驱动程序.这可能是问题的原因吗?

任何帮助将非常感激.如果您有任何需要,请告诉我.

Ps我看了下面的帖子,但遗憾的是没有帮助:
Raspberry Pi ad-hoc网络

编辑:/ etc/network/interfaces的内容:

两个当前设置节点都具有相同的内容:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Run Code Online (Sandbox Code Playgroud)

编辑:两个节点的/etc/wpa_supplicant/wpa_supplicant.conf的内容:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
Run Code Online (Sandbox Code Playgroud)

编辑:两个节点的ifconfig,iwconfig和路由:

节点1

ifconfig

wlan0    Link encap: Ethernet  HWaddr 80:1f:02:9b:bc:6c
         inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:0  errors:0  dropped:1  overruns:0  frame:0
         TX …
Run Code Online (Sandbox Code Playgroud)

networking wireless adhoc raspberry-pi mesh-network

5
推荐指数
2
解决办法
2万
查看次数

在C ++ 17中,&lt;cmath&gt;函数是否必须为`noexcept`?

在优化代码的某些部分时,我决定检查是否可以将某些方法声明为noexcept,这归结为我对的数学函数的不完全了解<cmath>

因此,我决定检查我使用的sin()asin()(例如)是否为noexcept

static_assert(noexcept(asin(1)));
static_assert(noexcept(sin(1)));
Run Code Online (Sandbox Code Playgroud)

它成功通过了,所以它们实际上是noexcept。我还查看了标准库实现中的相应定义:

template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
asin(_A1 __lcpp_x) _NOEXCEPT {return ::asin((double)__lcpp_x);}
Run Code Online (Sandbox Code Playgroud)

noexcept至少在我当前正在使用的实现中,这证实了它们的正确性。

但是,我无法确定这是否是标准要求的保证行为。因此,我想知道是否是必需的行为。如果不是这样,不要求他们成为的动机是noexcept什么?

通常的参考书cppreference.com没有列出noexcept这些功能(请参见比较)。与C的兼容性可能会引起一些混淆;但是,我找不到令人信服的逻辑,因为<cmath>显然使用C ++标头,而不是C兼容标头。

c++ c++-standard-library noexcept c++17

5
推荐指数
1
解决办法
120
查看次数