我正在尝试检查包含二进制格式化消息的缓冲区,但也包含字符串数据.举个例子,我正在使用这个C代码:
int main (void) {
char buf[100] = "\x01\x02\x03\x04String Data\xAA\xBB\xCC";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想得到一个十六进制转储的内容buf
,其格式类似于xxd
(我不在乎它是否完全匹配,我真正想要的是与可打印字符并排的十六进制转储).
在GDB里面我可以使用类似的东西:
(gdb) x /100bx buf
0x7fffffffdf00: 0x01 0x02 0x03 0x04 0x53 0x74 0x72 0x69
0x7fffffffdf08: 0x6e 0x67 0x20 0x44 0x61 0x74 0x61 0xaa
0x7fffffffdf10: 0xbb 0xcc 0x00 0x00 0x00 0x00 0x00 0x00
0x7fffffffdf18: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7fffffffdf20: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7fffffffdf28: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x7fffffffdf30: 0x00 0x00 …
Run Code Online (Sandbox Code Playgroud) 所以我正在从"void*"中读取dynamic_cast的答案,虽然你不能从一个响应void *
转换为T *
几个响应,但指出可以将一个转换T *
为a void *
,但是不要给出任何指示为什么你'我想这样做.
这只是一个琐事,它是否可能,或者是否有意义?我想也许是为了可读性或明确表示我们正在转换为a void *
,但鉴于其目的dynamic_cast
,它并不适合我.
对于这个问题,是没有任何理由做其他任何事情比让T *
变得void *
含蓄?void *
为了这个目的,我已经看过不时使用C风格的强制转换,我认为只是为了明确(假设我们没有做一些不寻常的事情,比如投射int
到指针或其他东西).
是否可以在POM中指定构建项目所需的最小Maven版本?
由于旧版Maven中的错误导致大型工件(> 2GB)被无声地截断,我们一直在浪费大量时间来追逐构建项目的人员的问题.不出所料,这些往往会导致最终产品中出现奇怪和破碎的行为.
是的,我们已经声明3.2.5是我们打算支持的最低版本,但我想知道:如果版本低于那个,有没有办法让Maven保释?我估计我可以轻松编写一个插件来执行此操作,但这似乎有点矫枉过正.所以,我希望有一个更简单的方法.
如果我写下面的代码:
#include <iostream>
using namespace std;
int main()
{
cout << &(int &&)123 << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后g++
抱怨:
foo.cc: In function ‘int main()’:
foo.cc:7:20: error: taking address of xvalue (rvalue reference)
Run Code Online (Sandbox Code Playgroud)
好的,多亏了什么是右值,左值,x值,glvalues和prvalues?我得到一个xvalue意味着它即将"过期",这是有道理的.但是现在如果我这样做:
#include <iostream>
using namespace std;
int main()
{
const int &x = (int &&)123;
cout << &x << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这"工作"很好,将打印一个地址.所以,我有几个问题:
通常有一种方法可以知道右值参考的生命周期吗?
因此,在浏览 C99 标准的 n869 草案时,我偶然发现了这一部分:
6.10.7 空指令语义
形式的预处理指令
Run Code Online (Sandbox Code Playgroud)# new-line
没有效果。
所以,我写了这个程序来测试它:
#
#include <stdio.h>
#
int main(void)
{
puts("Hello, world!");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
果然gcc
,即使我一直发出警告等,也不会对这段代码感到厌烦。我意识到语言中还有一些其他的结构并不明显,比如初始化器、枚举定义等中允许的额外逗号,但这是有目的的(例如简化代码生成器的编写)。
但是,我看不出这有什么用。任何人都可以想出一个合理的用例/理由来拥有它吗?
我正在查看Android butterknife库中的一些代码,并在此处找到此代码段:
private static final List<Class<? extends Annotation>> LISTENERS = Arrays.asList(//
OnCheckedChanged.class, //
OnClick.class, //
OnEditorAction.class, //
OnFocusChange.class, //
OnItemClick.class, //
OnItemLongClick.class, //
OnItemSelected.class, //
OnLongClick.class, //
OnPageChange.class, //
OnTextChanged.class, //
OnTouch.class //
);
Run Code Online (Sandbox Code Playgroud)
我发现这有点奇怪,在每一行后看起来只是空注释,但没有注释文本.它让我想起了C宏中的一些延续线,但我之前从未遇到过这种问题.
这实际上是否完成了任何事情/这里有一些约定吗?
所以,我看到这个输出,我有点惊讶:
$ echo "a,b,c,d,e,f,g" | cut -d, -f-4
a,b,c,d
$ echo "a,b,c,d,e,f,g" | cut -d, -f6-
f,g
echo "a,b,c,d,e,f,g" | awk '{ print $0 | "cut -d, -f-4"; print $0 | "cut -d, -f6-"; }'
f,g
a,b,c,d
Run Code Online (Sandbox Code Playgroud)
(作为旁注,我意识到这是一件非常愚蠢的事情awk
,但它是我见过它的唯一命令!).
据我了解,这应该将记录分为两个命令 - 按顺序.但由于某种原因,输出看起来相反.如果我这样做
$ echo "a,b,c,d,e,f,g" | awk '{ print $0 | "echo hello"; print $0 | "echo goodbye"; }'
hello
goodbye
Run Code Online (Sandbox Code Playgroud)
然后一切都按照我的预期顺序进行.我认为这必定是某种竞争条件,但我很惊讶awk
不等待管道中的子命令完成.这是一个已知的使用问题awk
或者是什么问题gawk
?有没有办法避免这样的陷阱?
编辑:
我也尝试使用它mawk
......相同(反转)的结果,似乎两者都是一致的.
在阅读其中一个Linux标题时,我遇到了一些奇怪的事情<linux/rtnetlink.h>
:
/* RTnetlink multicast groups */
enum rtnetlink_groups {
RTNLGRP_NONE,
#define RTNLGRP_NONE RTNLGRP_NONE
RTNLGRP_LINK,
#define RTNLGRP_LINK RTNLGRP_LINK
RTNLGRP_NOTIFY,
#define RTNLGRP_NOTIFY RTNLGRP_NOTIFY
RTNLGRP_NEIGH,
#define RTNLGRP_NEIGH RTNLGRP_NEIGH
RTNLGRP_TC,
#define RTNLGRP_TC RTNLGRP_TC
RTNLGRP_IPV4_IFADDR,
#define RTNLGRP_IPV4_IFADDR RTNLGRP_IPV4_IFADDR
/* ... etc, pattern continues ... */
};
Run Code Online (Sandbox Code Playgroud)
我很难理解这里宏的原因或者它们会产生什么不同.这有什么用途?
我有一个Makefile,它提取了一系列tarball.现在规则写得像:
dirname:
tar zxvf file.tar.gz
Run Code Online (Sandbox Code Playgroud)
以及依赖于扩展的tarball引用的其他目标dirname
.但是,为每个tarball定义这样的规则是一种杂乱无章.所以,我正在尝试使用该eval
函数自动生成这些规则.我的尝试看起来像这样:
TARFILES = $(wildcard *.tar.gz *.tgz)
define extract_tmpl =
$(shell tar tf $(1) | head -1):
tar zxvf $(1)
endef
$(foreach file, $(TARFILES), $(eval $(call extract_tmpl, $(file))))
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.我正在测试这个tarball(在同一个目录中):
$ ls Python-2.6.6.tgz
Python-2.6.6.tgz
$ tar tf Python-2.6.6.tgz | head -1
Python-2.6.6/
$ make Python-2.6.6/
make-3.79.1-p7: *** No rule to make target `Python-2.6.6/'. Stop.
Run Code Online (Sandbox Code Playgroud)
它似乎应该对我有用,但说实话,我甚至不确定我怎么能看到它扩展到什么.这里有什么明显的错吗?
我有一个巨大的日志文件,有很多例外,我需要提取完整的堆栈跟踪和前后几行.如果这个工具是bash脚本,那将是完美的.例:
$16.02.2012 16:04:34 *INFO * [main] InitialContextInitializer: Reference bound: rmirepository (InitialContextInitializer.java, line 203)
16.02.2012 16:04:34 *ERROR* [main] StandaloneContainerInitializedListener: Error of StandaloneContainer initialization (StandaloneContainerInitializedListener.java, line 109)
java.lang.RuntimeException: Cannot instantiate component key=org.exoplatform.services.jcr.ext.script.groovy.GroovyScript2RestLoader type=org.exoplatform.services.jcr.ext.script.groovy.GroovyScript2RestLoader found at file:/home/roman/reports/backup/1.14.7-5636/rdbms/single/exo-tomcat_1.14.7-5636/exo-configuration.xml
at org.exoplatform.container.jmx.MX4JComponentAdapter.getComponentInstance(MX4JComponentAdapter.java:134)
at org.exoplatform.container.management.ManageableComponentAdapter.getComponentInstance(ManageableComponentAdapter.java:68)
at org.exoplatform.container.ConcurrentPicoContainer.getInstance(ConcurrentPicoContainer.java:468)
at org.exoplatform.container.ConcurrentPicoContainer.getComponentInstancesOfType(ConcurrentPicoContainer.java:366)
at org.exoplatform.container.CachingContainer.getComponentInstancesOfType(CachingContainer.java:111)
at org.exoplatform.container.LifecycleVisitor.visitContainer(LifecycleVisitor.java:151)
at org.exoplatform.container.ConcurrentPicoContainer.accept(ConcurrentPicoContainer.java:615)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.picocontainer.defaults.AbstractPicoVisitor.traverse(AbstractPicoVisitor.java:32)
at org.exoplatform.container.LifecycleVisitor.traverse(LifecycleVisitor.java:90)
at org.exoplatform.container.LifecycleVisitor.start(LifecycleVisitor.java:170)
at org.exoplatform.container.ConcurrentPicoContainer.start(ConcurrentPicoContainer.java:554)
at org.exoplatform.container.ExoContainer.start(ExoContainer.java:266)
at org.exoplatform.container.StandaloneContainer$3.run(StandaloneContainer.java:178)
at org.exoplatform.container.StandaloneContainer$3.run(StandaloneContainer.java:175)
at org.exoplatform.commons.utils.SecurityHelper.doPrivilegedAction(SecurityHelper.java:291)
at org.exoplatform.container.StandaloneContainer.getInstance(StandaloneContainer.java:174)
at org.exoplatform.container.StandaloneContainer.getInstance(StandaloneContainer.java:129)
at org.exoplatform.ws.frameworks.servlet.StandaloneContainerInitializedListener.contextInitialized(StandaloneContainerInitializedListener.java:104)
at …
Run Code Online (Sandbox Code Playgroud)