小编igo*_*ack的帖子

为什么有人为第一个参数定义宏,包括C中的逗号?

ev.hlibev 里面,我发现了一些看起来很奇怪但无法理解的宏:

173 # define EV_P  struct ev_loop *loop /* a loop as sole parameter in a declaration */
174 # define EV_P_ EV_P,                /* a loop as first of multiple parameters */
Run Code Online (Sandbox Code Playgroud)

作者将宏定义EV_P_EV_P,并将其用作函数定义中的第一个参数,如下所示:

int  ev_run (EV_P_ int flags EV_CPP (= 0));
Run Code Online (Sandbox Code Playgroud)

好奇为什么不只是写EV_P,而不是EV_P_,所以函数参数看起来更清楚用逗号:

int  ev_run (EV_P, int flags EV_CPP (= 0));
Run Code Online (Sandbox Code Playgroud)

这是C中的伎俩还是有其他原因?不熟悉C之前的Google,但仍然没有答案.

c libev

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

在Scala中编写级联if语句的更好方法?

JavaScript我们可以重写:

if (ua.isEmpty()) {
    return false;
}
else if (ua.contains('curl')) {
    return false;
}
Run Code Online (Sandbox Code Playgroud)

进入此以获得清晰的代码:

switch(true) {
    case ua.isEmpty():
        return false;
    case ua.contains('curl'):
        return false;
}
Run Code Online (Sandbox Code Playgroud)

有什么建议我们可以在Scala中做类似的事情吗?

scala

3
推荐指数
1
解决办法
103
查看次数

What's the difference between char[] and char[n] in C/CPP?

Trying to figure out string literal types in C/CPP

printf("%s\n", typeid("abc").name());
printf("%s\n", typeid(const char[]).name());
Run Code Online (Sandbox Code Playgroud)

print

A4_c
A_c
Run Code Online (Sandbox Code Playgroud)

Not familiar with C, is different length/capacity of array means different type in C? if yes, why could we pass char[n] as char[] when passing function parameters?

c++

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

为什么strtotime('今天')错误地得到了10分钟?

试试这段代码:

<?php
    echo date('Y-m-d H:m:s', strtotime('today'));
Run Code Online (Sandbox Code Playgroud)

我的期望是:

2014-10-08 00:00:00
Run Code Online (Sandbox Code Playgroud)

但结果是:

2014-10-08 00:10:00
Run Code Online (Sandbox Code Playgroud)

为什么以及如何获得期待的?

php strtotime

0
推荐指数
1
解决办法
42
查看次数

标签 统计

c ×1

c++ ×1

libev ×1

php ×1

scala ×1

strtotime ×1