首页 \ 问答 \ 是!var与var!= NULL相同?(Is !var the same as var != NULL?)

是!var与var!= NULL相同?(Is !var the same as var != NULL?)

我想知道如果varchar *那么varvar != NULL是一样的。

这是一个非常小的POC,表明它不是一回事(或者我做错了什么?),但我不明白为什么。

int main(void) {
    char *c = NULL;
    if(!c){
        printf("1\n");
    }else{
        printf("2\n");
    }

    if(c != NULL){
        printf("1\n");
    }else{
        printf("2\n");
    }
    return 0;
}

输出是

1
2

我在x64 Arch Linux,GCC 4.8.2上运行这个

编辑:要么我需要一些真正的睡眠,或者你们都误解了程序的实际输出! 请阅读几次。

!c意思是“如果c不是NULL”,它是假的,所以它应该在第一个if打印2 ,但它打印1

编辑:的确,我需要睡一会儿。 我不知道我在想什么。 谢谢你们!


I'm wondering if !var is the same as var != NULL if var is char *.

Here goes a really small POC that shows that it's not the same thing (or am I doing something wrong?) but I don't understand why.

int main(void) {
    char *c = NULL;
    if(!c){
        printf("1\n");
    }else{
        printf("2\n");
    }

    if(c != NULL){
        printf("1\n");
    }else{
        printf("2\n");
    }
    return 0;
}

The output is

1
2

I'm running this on a x64 Arch Linux, GCC 4.8.2

EDIT: Either I need some real sleep or you all are misreading the actual output of the program! Please read it a few times.

!c means "if c is not NULL", which is false, so it should print 2 in the first if, but it prints 1!

EDIT: Indeed, I need to get some sleep. I don't know what was I thinking about. Thank you all!


原文:https://stackoverflow.com/questions/19646557
更新时间:2023-07-13 10:07

最满意答案

尝试将mapped-request-headers="*"到通道适配器(主站和从站)。 JMS默认映射所有标头; ampq适配器没有。

如果这没有帮助; 打开DEBUG记录并通过两侧的流程跟踪消息。

如果你无法解决这个问题,请将日志发布到某个地方。


Try adding mapped-request-headers="*" to the channel adapters (master and slave). JMS maps all headers by default; the ampq adapters do not.

If that doesn't help; turn on DEBUG logging and follow the messages through the flow on both sides.

If you can't figure it out from that, post the log someplace.

相关问答

更多
  • @RabbitListener(queues = "sys.topic.login.message") public void process1(@Payload String message, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel)throws Exception { if(message.equals("1")){ int i = 1/0; } channel.basicAck(deliveryTag,fa ...
  • 好吧,你误解了一下container.setAdviceChain(new Advice[]{retryOperationsInterceptor()}); 。 它是针对消息处理过程中的业务错误: 与协议错误和连接断开相反,业务异常处理可能需要更多考虑和一些自定义配置,尤其是在使用事务和/或容器时。 在2.8.x之前,RabbitMQ没有死信行为的定义,因此默认情况下,由于业务异常而被拒绝或回滚的消息可以无限制地重新传递。 要在客户端限制重新传递的数量,一个选择是在侦听器的建议链中的StatefulRetr ...
  • 作业完成后,您可以关闭连接: @Autowired CachingConnectionFactory cachingConnectionFactory; ... cachingConnectionFactory.resetConnection(); 要么 context.getBean(CachingConnectionFactory.class).resetConnection(); 或者只是在作业完成时关闭应用程序上下文: context.close(); 其中任何一个都将关闭连接。 ...
  • Spring Integration实现了来自http://www.enterpriseintegrationpatterns.com/books1.html的模式,同时使用AMQP / RabbitMQ作为其众多传输之一。 我知道spring-amqp是AMQP客户端功能。 如果你不想使用弹簧。 然后我们有一个普通的Java客户端: https : //www.rabbitmq.com/java-client.html Spring Integration implements the patterns ...
  • 尝试将mapped-request-headers="*"到通道适配器(主站和从站)。 JMS默认映射所有标头; ampq适配器没有。 如果这没有帮助; 打开DEBUG记录并通过两侧的流程跟踪消息。 如果你无法解决这个问题,请将日志发布到某个地方。 Try adding mapped-request-headers="*" to the channel adapters (master and slave). JMS maps all headers by default; the ampq adapter ...
  • 我使用了RabbitMQ提供的客户端库(jar)。 这是否意味着我使用了由RabbitMQ客户端API /库“内部”使用的AMQP协议来连接到RabbitMQ代理? 是的,您使用过AMQP协议(可能); RabbitMQ没有在内部使用AMQP。 它使用AMQP将消息从您的应用程序发送到RabbitMQ,并从RabbitMQ发送到(您的)其他应用程序; 或相反亦然。 或者,使用AMQP需要遵循不同的路线吗? 除了使用API之外,您还可以将其用作Apache Camel或Spring Integration的扩 ...
  • 这并不容易,如果代理不可用,我们通常会使用JUnit @Rule跳过测试。 但是,我们确实有很多使用mock的测试,但您必须了解许多Spring AMQP内部使用它们。 您可以在项目本身中浏览测试用例。 有一次,我确实尝试过写一个模拟经纪人,但结果是工作太多了。 It's not particularly easy, we generally use a JUnit @Rule to skip the test if the broker's not available. However, we do ha ...
  • 使用分区,无论成功/失败,都应该返回StepExecution : @ServiceActivator public StepExecution handle(StepExecutionRequest request) { Long jobExecutionId = request.getJobExecutionId(); Long stepExecutionId = request.getStepExecutionId(); StepExecution stepExecution ...
  • 您的消费者没有发送结果...... @Override public void onMessage(Message message) { System.out.println("consumer output: " + message); } 将其更改为简单的POJO; 容器的MessageListenerAdapter将为您处理转换,并发送结果。 @Override public String handleMessage(String message) { System.out.prin ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)