我有这个代码有效:
#include <stdio.h>
#define A(x) x B
#define B(x) C(x,
#define C(x,y) y x)
int main( void ) {
printf( A("1") ("2") "3" );
}
Run Code Online (Sandbox Code Playgroud)
它打印132(A宏的点是交换括号中的参数后面的东西与之后的所有东西,直到另一个结束括号)
但如果我在另一个宏中使用它:
#define Z(x) x
printf( Z( A("1") ("2") "3" ) );
Run Code Online (Sandbox Code Playgroud)
我得到编译错误"未终止的函数式宏调用".
我意识到这是因为编译器试图Z独立处理参数,但我需要使用它的右括号作为标记.有没有办法让我在宏中工作?更改调用语法实际上不是一个选项.
ps在我得到任何回复谈论这是多么糟糕的事情之前,请放心:这不是真正的代码.制作用于define在C内部模拟新语言的玩具程序时出现的问题.
我试图从连接到系统USB端口的USB设备(例如pendrive)获取数据.在这里,我可以打开设备文件并读取一些随机原始数据.但我想获取像minicom/teraterm这样的数据.
请让我知道我可以使用哪些方法和库来成功完成,以及如何完成.
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <signal.h>
#include <sys/time.h>
int main()
{
short portfd=-1;
int n,f,len;
char buf[256],*s;
alarm(2);
#if defined(O_NDELAY) && defined(F_SETFL)
portfd = open("/dev/ttyUSB0", O_RDWR|O_NDELAY);
if (portfd >= 0){
/* Cancel the O_NDELAY flag. */
printf("port openend\n");
n = fcntl(portfd, F_GETFL, 0);
(void) fcntl(portfd, F_SETFL, n & ~O_NDELAY);
}
#else
portfd = open("/dev/ttyUSB0", O_RDWR);
#endif
if (portfd >= 0)
{
if (len == 0) len = strlen(s); …Run Code Online (Sandbox Code Playgroud) 当给定一个格式化为Instant的原生ISO-8601的字符串时,或者作为自纪元以来的整数毫秒,我ParamConverter提供了一个Instant(Date).这工作正常,但我还需要能够支持其他日期格式(客户很挑剔).
为了避免经典dd/mm/yyyy与mm/dd/yyyy歧义,我希望客户指定他们的首选格式作为请求*的一部分.例如:
GET http://api.example.com/filter?since=01/02/2000&dateformat=dd/mm/yyyy
Run Code Online (Sandbox Code Playgroud)
传递给一个看起来像这样的方法:
@GET
String getFilteredList( final @QueryParam( "since" ) Instant since ) {
...
}
Run Code Online (Sandbox Code Playgroud)
(为清楚起见省略了时间和时区部分)
所以我希望我ParamConverter<Instant>能够读取dateformat参数.
我已经能够使用设置ContainerRequestContext属性的过滤器和AbstractValueFactoryProvider类似的东西的组合,但是需要参数来应用自定义注释,并且不允许它与QueryParam/FormParam /等一起使用.它没那么有用了.
有没有办法从ParamConverter中获取其他参数或请求对象本身?
[*]在现实世界中,这将来自一系列预先批准的格式,但现在只是假设他们正在提供输入 DateTimeFormatter
为清楚起见,这是我的代码:
public class InstantParameterProvider implements ParamConverterProvider {
private static final ParamConverter<Instant> INSTANT_CONVERTER =
new ParamConverter<Instant>( ) {
@Override public final T fromString( final String value ) {
// This is where I would like to get the other parameter's …Run Code Online (Sandbox Code Playgroud) 我有一个对象层次结构,需要能够从基类克隆对象.我遵循了典型的CRTP模式,除了我还希望能够在孩子直接调用复制时返回子类.为此,我遵循了这里的建议:https://stackoverflow.com/a/30252692/1180785
它似乎工作正常,但Clang警告我,我有潜在的内存泄漏.我把代码减少到了这个MCVE:
template <typename T>
class CRTP {
protected:
virtual CRTP<T> *internal_copy(void) const {
return new T(static_cast<const T&>(*this));
}
public:
T *copy(void) const {
return static_cast<T*>(internal_copy());
}
virtual ~CRTP(void) = default;
};
class Impl : public CRTP<Impl> {
};
int main(void) {
Impl a;
Impl *b = a.copy();
delete b;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,那里没有可能的内存泄漏,但是通过XCode运行Clang显示了这一点:
是否有内存泄漏吗?如果不是,导致误报的原因是什么?我该如何解决?(我宁愿不关闭静态分析)
一个简化的例子:
HTML:
<div id="A">
<div id="B"></div>
<div id="C"></div>
<div id="D"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#A,#B,#C,#D{width:100px;height:100px}
#A{position:relative;width:220px;top:20px;left:20px;background:#FF0000}
#B{position:absolute;top:0;left:0;background:#FFFF00}
#C{position:absolute;top:10px;left:80px;background:#00FF00}
#D{position:absolute;background:#00FFFF;top:0;right:0}
Run Code Online (Sandbox Code Playgroud)
作为一个小提琴:http://jsfiddle.net/h6BNz/
好的C就是在前面B和后面D,并相对于A.我想将它相对于文档定位,但保持在B和D之间(在z-index和Tab顺序中).如果C位置改变为position:fixed,它完全符合我的要求,除了(显然)不滚动页面.
我已经看到很多解决方案涉及打破其父级的div来实现这一点,但这需要设置z-indices和tab order,这似乎是一个噩梦来管理(这是一个插件,所以周围的代码在外面我的控制).
我怎么可以给C没有打破一个真正的绝对位置B或D,或改变结构?JavaScript可以设置它,但我需要最终页面位置完美舍入(如果你对原因感兴趣,请参阅我的其他一些问题),所以我认为我不能使用absolutePosition - absolutePositionOfContainer方法.
我正在使用XDomainRequestIE8和9将请求发送到服务器.与XMLHttpRequests在其他浏览器,同时具有Origin和Referer头被发送,并且看起来是这样的:
Origin: http://www.example.com
Referer: http://www.example.com/mypage/index.htm
Run Code Online (Sandbox Code Playgroud)
但XDomainRequest只发送Origin(因此我没有看到完整的调用URL).有没有办法强制它也发送Referer?我试图避免将其作为查询字符串或POST参数发送.
我知道这XDomainRequest不允许自定义标头,但我希望因为Referer是标准标头,可能有一些方法来启用它.
我有一段代码来更新数据库中的记录.减少的例子:
...
statement = connection.prepareStatement(
"INSERT INTO thistable (name) VALUES (?)",
PreparedStatement.RETURN_GENERATED_KEYS
);
statement.setString( 1, "Fred" );
statement.addBatch( );
statement.setString( 2, "Joe" );
statement.addBatch( );
statement.executeBatch( );
...
Run Code Online (Sandbox Code Playgroud)
这是处理大量记录的一些代码的一部分,代码运行了很多线程以提高速度.这一切都很好,但随着现场环境的负载增加,我一直注意到有几个SQLTransientException被抛出.除了重试交易之外,似乎我无法做任何事情.
我的问题是:即使声明失败,批次是否已被清除?我可以简单地重试该executeBatch行,还是需要重新创建整批产品?对于非批处理语句,这是一样的吗?
简而言之,更一般地说,这是处理瞬态异常的好方法吗?
statement.setString( 1, "Fred" );
statement.addBatch( );
statement.setString( 2, "Joe" );
statement.addBatch( );
for( int attempt = 0; ; attempt ++ ) {
try {
statement.executeBatch( );
break;
} catch( SQLTransientException ex ) {
if( attempt >= 3 ) {
throw ex;
}
try …Run Code Online (Sandbox Code Playgroud) 我有一个基于 shell 的 concourse 任务,它在其中一个命令中使用半敏感凭据(测试服务器的密钥)。我想避免将其记录在任务输出中。
管道的要点是:
jobs:
- name: foobar
plan:
<...>
- task: build
config:
platform: linux
image_resource:
type: docker-image
source:
repository: ubuntu
<...>
run:
path: bash
args:
- -exc
- |
command-which-is-ok-to-print
foobar {{my-secret-data}} # <-- hide this one!
another-command-which-is-ok-to-print
Run Code Online (Sandbox Code Playgroud)
目前输出显示为:
+ command-which-is-ok-to-print
results of first command which are OK to print
+ foobar "oh-no-secret-data-here!" <-- hide this one!
more results which are OK to print
+ another-command-which-is-ok-to-print
even more results which are OK to print
Run Code Online (Sandbox Code Playgroud)
有没有办法抑制打印此特定行?
我有一个简单的 C++ 项目,依赖于 Intel TBB(需要使用共享库)。我正在尝试使用 Conan 包管理器与 CMake 结合来构建它,并且我已经能够使用此设置来添加非共享依赖项,没有任何问题。
我的第一次尝试(结合conan 的 conanfile.txt 使用包的文档和conan 的 conanfile.py 参考指南中的信息)使用了conanfile.py如下内容:
import os
from conans import ConanFile, CMake
class MyProjectConan(ConanFile):
settings = 'os', 'compiler', 'build_type', 'arch'
requires = 'TBB/2018_U6@conan/stable'
generators = 'cmake'
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def imports(self):
self.copy('*.dll', src='bin', dst='bin')
self.copy('*.dylib*', src='lib', dst='bin')
self.copy('*.so', src='lib', dst='bin')
Run Code Online (Sandbox Code Playgroud)
和CMakeLists.txt这样的:
cmake_minimum_required(VERSION 2.8.12)
project(MyProject)
add_definitions("-std=c++17")
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(main src/main.cpp)
target_link_libraries(main ${CONAN_LIBS})
Run Code Online (Sandbox Code Playgroud)
(我的src/main.cpp只是TBB 包的测试文件的直接副本)
这个构建得很好; …
我正在将 Google 登录集成到我的网络应用程序中,但无论我指定什么,它总是在登录流程中显示警告:
要继续,Google 将与 [应用名称] 分享您的姓名、电子邮件地址和个人资料照片。
我不需要也不想要我的用户的姓名、电子邮件地址或个人资料图片;我只需要一个 token_id。我知道一个类似的问题,其中开发人员只需要电子邮件地址,并且解释说其他详细信息无论如何都可以从电子邮件地址派生,但在这种情况下,我也不想要电子邮件地址。
按照我设置的文档:
function login() {
gapi.auth2.init({
client_id: myClientIdHere,
cookie_policy: 'none',
fetch_basic_profile: false, // <-- remove basic profile
scope: 'openid', // <-- request only openid
ux_mode: 'redirect', // <-- using redirect to avoid popup blocker issues
redirect_uri: myRedirectUriHere,
}).then((GoogleAuth) => {
GoogleAuth.signIn() // [etc]
});
}
function init() {
gapi.load('auth2', login);
}
Run Code Online (Sandbox Code Playgroud)
检查网络请求表明这将用户引导至:
这看起来是正确的。我尝试调整该 URL 并手动导航到它,无论我如何更改它似乎总是显示警告。
在 Credentials -> OAuth 同意屏幕 -> Scopes for Google APIs 下的我的 Google …