说我有一个字符数组:
#define LEN 10
char arr[LEN + 1];
Run Code Online (Sandbox Code Playgroud)
让我们做一些scanf操作:
scanf("Name: %s", arr);
Run Code Online (Sandbox Code Playgroud)
如果有人输入的名称超过10个字符,这可能会很危险.所以最好用这个:
scanf("Name: %10s", arr);
Run Code Online (Sandbox Code Playgroud)
那么现在如果LEN改变我会遇到麻烦.我将不得不通过整个代码来纠正我10在上下文中使用的每一行arr.所以我想到了这样的事:
scanf("Name: %LENs", arr);
Run Code Online (Sandbox Code Playgroud)
但这不起作用.LEN由于在字符串中使用,因此预处理器无法解析.
如何在格式字符串中使用define?
我在将微控制器上的一些数据从一个结构复制到另一个结构时遇到了硬错误异常.我尝试了不同的实现,它们应该完全相同.看我的代码行:
memcpy(&msg.data, data, 8);
memcpy(&msg.data, data, sizeof(*data));
memcpy(&msg.data, data, sizeof(msg.data));
msg.data = *data; // Hard Fault
Run Code Online (Sandbox Code Playgroud)
前三行工作得很好.最后一个以硬故障异常结束.线的组装memcpy是相同的.直接分配的程序集有所不同:
memcpy(&msg.data, data, sizeof(msg.data));
800c480: f107 030c add.w r3, r7, #12
800c484: 330b adds r3, #11
800c486: 2208 movs r2, #8
800c488: 6879 ldr r1, [r7, #4]
800c48a: 4618 mov r0, r3
800c48c: f7f4 f82e bl 80004ec <memcpy>
msg.data = *data; // Hard Fault
800c490: 687b ldr r3, [r7, #4]
800c492: f107 0217 add.w r2, r7, #23
800c496: cb03 ldmia r3!, {r0, …Run Code Online (Sandbox Code Playgroud) 运行git log给我这样的输出:
commit 69b6309f09365c09a2fe10f09aee801d1fae29ee (HEAD -> master, edeviserBranch)
Author: eDeviser <eDeviser@xyz.com>
Date: Mon Sep 2 09:53:07 2019 +0200
added foo
commit 59a08270fb730db259a8d5819bb585a613024d97 (origin/master, origin/HEAD)
Author: eDeviser <eDeviser@xyz.com>
Date: Mon Sep 2 09:49:50 2019 +0200
More Text
Run Code Online (Sandbox Code Playgroud)
我不明白括号内内容的含义。括号内的文字是什么意思?这是提交所基于的分支吗?HEAD -> master如果是,和origin/master之间有什么区别origin/HEAD?
如何解释git日志中的括号?
我添加了一个 udev 规则来生成到特殊 tty 设备的单独链接。我从 lsusb 获取了供应商和产品 ID:
Bus 001 Device 016: ID abcd:1234 Foo Device
Run Code Online (Sandbox Code Playgroud)
该dmesg设备的输出是:
[ 369.384850] usb 1-1.1: new full-speed USB device number 4 using xhci_hcd
[ 369.470492] usb 1-1.1: New USB device found, idVendor=09d8, idProduct=0420
[ 369.470506] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 369.470515] usb 1-1.1: Product: TWN4/B1.06/CCL3.12/PRS1.04
[ 369.470522] usb 1-1.1: Manufacturer: OEM
[ 369.475188] cdc_acm 1-1.1:1.0: ttyACM0: USB ACM device
Run Code Online (Sandbox Code Playgroud)
通常 Debian 系统会为此设备生成一个 ACM* tty:
$ ls /dev/ttyACM* …Run Code Online (Sandbox Code Playgroud) 该猫的手册页 说:
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
Run Code Online (Sandbox Code Playgroud)
M标记是什么,在哪里记录?
例:
$cat log -A
wrote 262144 bytes from file test.x in 9.853947s (25.979 KiB/s)^M$
^M> ^H^H ^H^H>
Run Code Online (Sandbox Code Playgroud)
什么意思^M和^H?
我正在为我的项目使用 Makefile。我需要我的 makefile 将日期和我的计算机名称回显到文件中:
files:
echo " * Author: $(whoami)" >> myFile
echo " * Created on: $(date +%D)" >> myFile
Run Code Online (Sandbox Code Playgroud)
我假设一个文件如下所示:
* Author: eDeviser
* Created on: 02.01.2017
Run Code Online (Sandbox Code Playgroud)
尽管如此,它看起来是这样的:
* Author:
* Created on:
Run Code Online (Sandbox Code Playgroud)
我尝试将这两行直接输入到我的终端中。这非常有效:
$echo " * Author: $(whoami)" >> myFile
$echo " * Created on: $(date +%D)" >> myFile
$cat myfile
* Created on: 01/02/17
* Author: lukas
Run Code Online (Sandbox Code Playgroud)
我的错误在哪里?
我在做什么:
我正在使用cmocka对大型嵌入式项目运行单元测试。嵌入式项目使用编译arm-gcc-compiler。单元测试是gcc使用嵌入代码和cmocka库的片段与普通代码一起编译的。
通常,cmocka建议使用该-Wl,--wrap=functionName标志来模拟(替换)一些不需要的子功能。这个效果很好。
问题:
好吧,在我的嵌入式代码中,有一个头文件(foo.h),其中包含一些函数(声明为内联)。这些函数之一包含的一些汇编代码arm-gcc-compiler,当然,这些不能被编译gcc。
愣神的wrap-flag似乎并没有被放置在头文件中的函数工作。
题:
如何在头文件中模拟该功能呢?
我如何解决问题:
我考虑过要插入一些#idef宏以排除提到的汇编器部分。但这无法完成,因为此文件属于许可库,并且不允许更改其内容。
我可以将待测函数提取到其他文件中,这样foo.h就不再需要包含它了。但这会混淆嵌入式源代码的结构。
确切的问题
确切的代码位于233行的freeRtos的portmacro.h中:
portFORCE_INLINE static void vPortRaiseBASEPRI( void )
{
uint32_t ulNewBASEPRI;
__asm volatile
(
" mov %0, %1 \n" \
" msr basepri, %0 \n" \
" isb \n" \
" dsb \n" \
:"=r" (ulNewBASEPRI) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY )
);
}
Run Code Online (Sandbox Code Playgroud)
其中portFORCE_INLINE定义为:
#define portFORCE_INLINE inline …Run Code Online (Sandbox Code Playgroud) gcc 6.3 的手册页说:
--wrap=symbol
Use a wrapper function for symbol. Any undefined reference to
symbol will be resolved to "__wrap_symbol". Any undefined
reference to "__real_symbol" will be resolved to symbol.
...
If you link other code with this file using --wrap malloc, then all
calls to "malloc" will call the function "__wrap_malloc" instead.
The call to "__real_malloc" in "__wrap_malloc" will call the real
"malloc" function.
Run Code Online (Sandbox Code Playgroud)
所以我创建了一个简单的例子:
#include <stdio.h>
int foo() {
printf("foo\n");
return 0;
}
int __wrap_foo() {
printf("wrap foo\n"); …Run Code Online (Sandbox Code Playgroud) 我正在使用 cpplint 根据谷歌风格指南检查我的源代码。
Cpplint 的帮助说:
cpplint.py supports per-directory configurations specified in CPPLINT.cfg
files. CPPLINT.cfg file can contain a number of key=value pairs.
Currently the following options are supported:
"exclude_files" allows to specify a regular expression to be matched against
a file name. If the expression matches, the file is skipped and not run
through liner.
Example file:
filter=-build/include_order,+build/include_alpha
exclude_files=.*\.cc
The above example disables build/include_order warning and enables
build/include_alpha as well as excludes all .cc from being
processed by linter, in …Run Code Online (Sandbox Code Playgroud) 我有一个 Makefile,需要使用 awk 从文本文件 `someText.txt 中提取一些信息。这是一个例子:
在控制台中手动对我的文本文件执行 awk 效果很好:
$ cat someText.txt | awk '/Total number:/ {print $NF}'
$ 42
Run Code Online (Sandbox Code Playgroud)
但在我的 makefile 中使用它不起作用:
MYVAR=$(shell cat someText.txt | awk '/Total number:/ {print $NF}')
all:
@echo Count: $(MYVAR)
Run Code Online (Sandbox Code Playgroud)
输出是:Count:
但我建议输出是Count: 42
我尝试更新一些 svn 目录。但突然svn挂起,没有任何输出消息。
我按下ctrl-z并做了一个ps aux | grep svn。svn 进程挂起SL。
现在做什么?如何获得一些错误输出?
我已经尝试检查其他一些存储库,但这最终导致了相同的行为。
这是完整的ps aux | grep svn:
other 7910 0.0 0.3 136732 12316 ? SL Jun25 0:20 svn log ../tags/
other 8004 0.0 0.3 136732 12332 ? SL Jun25 0:20 svn log ../tags/
other 8090 0.0 0.2 136824 11804 ? SL Jun25 0:20 svn up
other 17754 0.0 0.2 136824 11612 ? SL Jun25 0:20 svn up
other 26844 0.0 0.2 …Run Code Online (Sandbox Code Playgroud) c ×4
gcc ×2
makefile ×2
awk ×1
c++ ×1
cat ×1
cmocka ×1
command-line ×1
cpplint ×1
echo ×1
gcc-warning ×1
git ×1
linker-flags ×1
linux ×1
linux-kernel ×1
memcpy ×1
regex ×1
shell ×1
stm32 ×1
struct ×1
svn ×1
tty ×1
ubuntu ×1
ubuntu-17.10 ×1
udev ×1
unit-testing ×1
usb ×1