是!var与var!= NULL相同?(Is !var the same as var != NULL?)
我想知道如果
var
是char *
那么var
和var != 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 asvar != NULL
ifvar
ischar *
.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 "ifc
is not NULL", which is false, so it should print2
in the firstif
, but it prints1
!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
最满意答案
尝试将
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 ...
-
Rabbit连接不会关闭(Rabbit connection won't close)[2021-06-01]
作业完成后,您可以关闭连接: @Autowired CachingConnectionFactory cachingConnectionFactory; ... cachingConnectionFactory.resetConnection(); 要么 context.getBean(CachingConnectionFactory.class).resetConnection(); 或者只是在作业完成时关闭应用程序上下文: context.close(); 其中任何一个都将关闭连接。 ... -
Spring集成pubsub vs Spring amqp RabbitMQ pubsub(Spring integration pubsub vs Spring amqp RabbitMQ pubsub)[2023-05-08]
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 ... -
使用AMQP(Rabbit)进行Spring批量集成远程分块(Spring batch integrarion remote chunking using AMQP (Rabbit))[2022-07-03]
尝试将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 ... -
AMQP - Rabbit MQ用法(AMQP - Rabbit MQ usage)[2022-12-12]
我使用了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 ...
-
spring amqp rabbitmq MessageListener无效(spring amqp rabbitmq MessageListener not working)[2022-09-27]
您的消费者没有发送结果...... @Override public void onMessage(Message message) { System.out.println("consumer output: " + message); } 将其更改为简单的POJO; 容器的MessageListenerAdapter将为您处理转换,并发送结果。 @Override public String handleMessage(String message) { System.out.prin ...