我有一个像这样的awk代码:
val = and($1, 0x03FFFFFF) + $2
Run Code Online (Sandbox Code Playgroud)
我写了这样的Perl版本:
$val = ($1 && 0x03FFFFFF) + $2;
Run Code Online (Sandbox Code Playgroud)
这条线是一样的吗?
我有以下代码.构建应用程序是myprogram.
如果我启动myprogram然后killall myprogram,然后我立即启动myprogram,然后myprogram崩溃.
崩溃原因是由于第一次启动创建的管理线程在第二次启动之前未正确清除.
所以在第二次启动时,myprogram试图用pthread创建线程,旧的线程管理还没有被删除,所以它会导致崩溃.
有没有办法在我第一次启动时或在我第二次使用C启动时开始杀死管理线程?
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
pthread_t test_thread;
void *thread_test_run (void *v)
{
int i=1;
while(1)
{
printf("into thread %d\r\n",i);
i++;
sleep(1);
}
return NULL
}
int main()
{
// ps aux | grep myprogram ---> show 1 myprogram (1 for the main application)
pthread_create(&test_thread, NULL, &thread_test_run, NULL);
// ps aux | grep myprogram ---> show 3 myprogram
// (1st for the main application)
// (2nd for the management thread. …Run Code Online (Sandbox Code Playgroud) 我知道填充,它的规则,它为什么需要等.
我的问题是结构,
struct my_struct {
int a;
char c;
};
Run Code Online (Sandbox Code Playgroud)
在这种情况下,c的起始地址是字对齐,但仍然编译器添加3个字节(假设4作为字大小)填充.在c之后没有元素,为什么我们需要这3个字节?我查了下面的,
int g_int1;
struct my_struct st;
int g_int2;
Run Code Online (Sandbox Code Playgroud)
通过以上我的意思是我的其余变量声明不依赖于先前变量大小的单词align-ness.编译器总是尝试对齐下一个变量,而不管其全局或局部自动变量.
我看不出有任何关于endian-ness的原因,因为这是char并且对于一个字节它并不重要.我认为是什么原因而不是检查最后一个元素条件编译器总是在需要时添加填充.
什么能有正当理由?
我有一些MP4格式的视频文件,我想将它们转换为MPEG格式文件.
我尝试转换为:
avconv -i 1.mp4 -fmp4 -target mpeg /mpeg/1.mpeg
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误
1.mp4: Invalid data found when processing input
Run Code Online (Sandbox Code Playgroud)
我的命令中缺少什么?
假设我有一个char*被调用的代码,它包含"0x41"在其中。
char *code = "0x41";
Run Code Online (Sandbox Code Playgroud)
我怎样才能把它转换成一个unsigned int?(确切地说,我需要一个WORD,但这只是一个unsigned int)。
我正在尝试使用wait()和fork()我的c ++代码.但是我在编译阶段遇到以下错误
../test/my_test.cpp: In member function 'void MYClass::myMethod()':
../test/my_test.cpp:98: error: no matching function for call to 'wait::wait(int*)'
/data/backfire/staging_dir/toolchain-i386_gcc-4.1.2_uClibc-0.9.30.1/lib/gcc/i486-openwrt-linux-uclibc/4.1.2/../../../../i486-openwrt-linux-uclibc/sys-include/bits/waitstatus.h:68: note: candidates are: wait::wait()
/data/backfire/staging_dir/toolchain-i386_gcc-4.1.2_uClibc-0.9.30.1/lib/gcc/i486-openwrt-linux-uclibc/4.1.2/../../../../i486-openwrt-linux-uclibc/sys-include/bits/waitstatus.h:68: note: wait::wait(const wait&)
Run Code Online (Sandbox Code Playgroud)
码:
void MYClass::myMethod()
{
pid_t pid;
int status;
if ((pid = fork()) < 0) {
printf("error fork\n");
return;
}
if (pid == 0) {
/* cild*/
......
}
/*parent*/
while (wait(&status) != pid);
}
Run Code Online (Sandbox Code Playgroud)
如何修复错误?
我有以下alogorithm,我想在lua中实现它.我锁定了如何在lua中实现按位运算.
void wepkey64(char *passphrase, unsigned char k64[4][5])
{
unsigned char pseed[4] = {0};
unsigned int randNumber, tmp;
int i, j;
for(i = 0; i < strlen(passphrase); i++)
{
pseed[i%4] ^= (unsigned char) passphrase[i];
}
randNumber = pseed[0] | (pseed[1] << 8) | (pseed[2] << 16) | (pseed[3] << 24);
for (i = 0; i < 4; i++)
{
for (j = 0; j < 5; j++)
{
randNumber = (randNumber * 0x343fd + 0x269ec3) & 0xffffffff;
tmp = (randNumber >> …Run Code Online (Sandbox Code Playgroud) 如何让开关执行2个案例?
我尝试使用以下代码,但它只执行第一种情况
#!/bin/sh
action="titi"
case "$action" in
toto|titi)
echo "1_$action"
;;
tata|titi)
echo "2_$action"
;;
esac
Run Code Online (Sandbox Code Playgroud) 我有一个用git下载的代码.在代码中,我使用以下命令为我的修改创建了一个新分支:
git checkout -b branch_5
Run Code Online (Sandbox Code Playgroud)
完成文件编辑后,我做了一个本地提交
git commit -a
Run Code Online (Sandbox Code Playgroud)
然后我创建了补丁.但是我无法在生成的补丁文件中看到历史记录中新分支的名称.
任何解释?我在创建新分支时遗漏了什么吗?
我在哪里可以找到有关新分支的信息?
是否可以知道以下命令的输出是否为空?
cat anyfile.txt | grep anymessage
Run Code Online (Sandbox Code Playgroud)
不将显示的输出放入变量,也不将显示的输出重定向到文件