我正在尝试获取已安装软件包的版本号,以便为dpkg构建依赖项列表.
如果我在我的终端输入"dpkg -l | grep libqtcore4",我会得到以下结果:
ii libqtgui4 4:4.7.4-0ubuntu8 Qt 4 GUI module
ii libqtgui4:i386 4:4.7.4-0ubuntu8 Qt 4 GUI module
Run Code Online (Sandbox Code Playgroud)
我的问题是; 冒号(:)在版本号中是什么意思,-0ubuntu最终意味着什么?
我在第14课就着名的" 学习C艰难之路 "在线课程.
在该课程中,它介绍了前向声明的概念C.代码示例中有两个前向声明.其中一个可以被注释掉,代码仍然编译,但另一个不能被注释掉.对我来说,他们看起来同样重要.
这是代码.它只是打印出所有字符及其十六进制代码(如果它们来自字母表),否则它会跳过它们.
两个编译器输出位于代码的底部.有人可以解释为什么一个错误出来而另一个错误?
#include <stdio.h>
#include <ctype.h>
// forward declarations
int can_print_it(char ch); //NOT OK to skip(??)
void print_letters(char arg[]); //OK to skip(??)
void print_arguments(int argc, char *argv[])
{
int i = 0;
for(i = 0; i < argc; i++) {
print_letters(argv[i]);
}
}
void print_letters(char arg[])
{
int i = 0;
for(i = 0; arg[i] != '\0'; i++) {
char ch = arg[i];
if(can_print_it(ch)) {
printf("'%c' == %d ", ch, ch);
}
}
printf("\n"); …Run Code Online (Sandbox Code Playgroud) 我正在从Learn C the Hard way在线课程中吸取教训.在下面的代码示例中,我不明白为什么这两个free()调用是必要的.我以为只需要拨打free()一次,因为只有一次malloc()发生.有人可以澄清我们为什么需要两个吗?
如果我发表评论free(who->name);然后valgrind告诉我,我已经失去了一大块记忆,就像这样;
LEAK SUMMARY:
definitely lost: 21 bytes in 2 blocks
Run Code Online (Sandbox Code Playgroud)
这是代码:
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
struct Person {
char *name;
int age;
int height;
int weight;
};
struct Person *Person_create(char *name, int age, int height, int weight)
{
struct Person *who = malloc(sizeof(struct Person));
assert(who != NULL);
who->name = strdup(name);
who->age = age;
who->height = height;
who->weight = weight; …Run Code Online (Sandbox Code Playgroud) 这里有新手问题.
我正在看一个u-boot boardfile,它有很多功能.
例如; board_mmc_init(), enet_board_init(), setup_splash_img(),等等
大多数这些函数都不会从boardfile中调用.他们从其他地方打来电话.但我无法弄清楚在哪里.
在Linux内核板文件中有一个机器结构.在那里,我们可能有.init_machine = myboard_init.那么myboard_init(void)就会调用其他函数这将反过来通话等功能.我发现这种风格很容易阅读.
我的问题是; 确实u-boot有一个相当于.init_machine? 我在哪里看到一切'开始'?谁将所有那些松散的函数调用在u-boot中boardfile?
-Andy
只是一个简单的问题.在我的i2c上bus 0,我有两个设备,0x32和0x20.
当我使用i2cdetect时,只显示其中一个.
# ./i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- …Run Code Online (Sandbox Code Playgroud) 我有一个程序,其系统调用getpwnam()在运行时失败。为了调试此代码,我决定单独运行getpwnam()以下代码(它来自一个论坛):
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
struct passwd *pw;
if (argc != 2) {
printf("usage: %s username\n", argv[0]);
exit(0);
}
pw = getpwnam(argv[1]);
if (pw == NULL)
printf("getpwnam failed\n");
else
printf("home dir = %s\n", pw->pw_dir);
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,它似乎依赖于libnss_compat-2.3.5.so存在:
使用libnss_compat:
./pwnam root
home dir = /root
如果没有libnss_compat:
./pwnam root
getpwnam failed
所以我的问题是;为什么要getpwnam()依赖libnss_compat*.so?我发现了提供的lib nm -D命令。libc-2.3.5.sogetpwnam()
readelf -d告诉我libc反过来仅取决于ld.so.1。反过来,这无关紧要。那么为什么在地球 …
我不确定我的问题是 Linux 问题还是与操作系统无关的问题。
如果我运行了三个进程(我们称它们为 P0、P1 和 P2),并且它们在用户看来是同时运行的,那么它们如何共享?
他们每个人都在用户空间内维护自己的堆栈、堆等吗?
或者他们只是拥有整个堆栈、堆等,直到下一个进程出现并抢占它?