我知道I2C和SPI通信的基本知识.由于两者都是同步协议.我想知道是什么让SPI比I2C更快.如果我没有使用I2C,我们可以使用400kbps,而在SPI中我们也可以达到10mbps.是因为硬件变化了吗?在一次采访中我问过这个问题.如果我错了,请告诉我.
嵌入式系统的意思是什么?
如果我们制作的系统/机器或产品用于多种用途,那么我们可以将其视为嵌入式系统吗?或者只是一个专门用于特定任务的系统被视为嵌入式系统?PC /移动/笔记本电脑可以被视为嵌入式系统吗?
我最近遇到了这个面试问题,我不善于操控.你能解释一下'f'的功能吗?我不确定这个递归函数是做什么的.
unsigned int f (unsigned int a , unsigned int b)
{
return a ? f ( (a&b) << 1, a ^b) : b;
}
Run Code Online (Sandbox Code Playgroud)
我试图在Visual Studio中粘贴代码来测试逻辑但是编译器抛出了一些错误消息"无法隐式地将类型'uint'转换为'bool'.条件语句(a?)在返回中丢失了什么?但是我'我确定面试问题与上面提到的完全相同
我能够从这里找出逻辑:
r = y ^ ((x ^ y) & -(x < y)); // min(x, y)
r = x ^ ((x ^ y) & -(x < y)); // max(x, y)
Run Code Online (Sandbox Code Playgroud)
它说这比做更快
r = (x < y) ? x : y
Run Code Online (Sandbox Code Playgroud)
有人可以通过示例来解释它以了解它.怎么可能更快?
我对此Misra警告有两个用例,如下所述。编译器是否为#if定义保留了某些名称或特定名称而不能使用?
目前,我已禁用此警告,//lint !e9071但是我们真的需要对此类警告采取任何措施吗?如果我们禁用此类警告,将会有任何影响或风险吗?
情况1:
#ifndef __CCPPAR_H__
#define __CCPPAR_H__ //lint !e9071
#include "Ccp_Cfg.h"
#endif /* multiple inclusion protection - __CCPPAR_H__ */
Run Code Online (Sandbox Code Playgroud)
观察到的警告:
Run Code Online (Sandbox Code Playgroud)defined macro '__CCPPAR_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required]
情况2:
#ifndef __CCP_H__
#define __CCP_H__ //lint !e9071
#include "Ccppar.h"
#define MAJOR 0x02
#define MINOR 0x01
/* other parts of code */
#endif
Run Code Online (Sandbox Code Playgroud)
观察到以下Misra警告:
Run Code Online (Sandbox Code Playgroud)defined macro '__CCP_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required]
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
int main(void)
{
pid_t Checksum_pid = fork();
if (Checksum_pid < 0)
printf("Fork Failed\n");
else if (Checksum_pid == 0)
{
printf("\nInside Child Process before execl");
//execl("/bin/sleep", "/bin/sleep", "2", NULL);
execl("/bin/ls","ls",(char *)NULL) ;
//exit(EXIT_FAILURE);
printf("\nInside Child Process after execl\n");
exit(EXIT_FAILURE);
}
else
{
int childStatus;
printf("\nInside Parent Process");
sleep(5);
pid_t returnValue = waitpid(Checksum_pid, &childStatus, WNOHANG);
if (returnValue > 0)
{
if (WIFEXITED(childStatus))
printf("\nChild Exit Code: %d\n", WEXITSTATUS(childStatus));
else
printf("\nChild Exit Status: 0x%.4X\n", …Run Code Online (Sandbox Code Playgroud) 据我所知,如果 waitpid 返回 -1,则它是错误条件。如何从 WEXITSTATUS(childStatus) 中的子进程获得成功 (EXIT_SUCCUSS)?
waitpid 中的 childStatus 与 WEXITSTATUS(childStatus) 的返回值有什么区别?一样吗?
pid_t returnValue = waitpid(Checksum_pid, &childStatus, WNOHANG);
printf("return value = %d", returnValue);
printf("return value = %d", childStatus);
if (WIFEXITED(childStatus))
{
printf("Exit Code: _ WEXITSTATUS(childStatus)") ;
//Proceed with other calculation.
}
Run Code Online (Sandbox Code Playgroud) 我使用如下的函数指针数组来避免switch代码中的语句。
void E_func1(void);
void E_func2(void);
void E_func3(void);
void (*pfGetVal[3])() = {
E_func1,
E_func2,
E_func3
};
Run Code Online (Sandbox Code Playgroud)
但是在运行 misra (pclint) 时,我收到以下错误:
函数指针和另一种类型之间的转换 [MISRA 2012 规则 11.1,需要]
我需要使用typedef吗?
我尝试如下,但没有奏效。
void (*pfGetVal[3])();
pfGetVal[0] = E_func1;
pfGetVal[1] = E_func2;
pfGetVal[2] = E_func3;
Run Code Online (Sandbox Code Playgroud) 我没有在我的代码中处理SIGCHLD.终止后,我的流程仍然立即删除.我希望它成为僵尸进程.如果我将SIGCHLD设置为SIGDFT那么,它是否行得通呢?我如何将SIGCHLD设置为SIGDFT?我希望进程变成僵尸,所以我可以在waitpid之后读取父进程中的子状态.
#define MAXSTR "Maximum number reached"
char *str = MAXSTR;
Run Code Online (Sandbox Code Playgroud)
在做这种操作的同时.代码工作正常,但我得到lint错误.我怎么解决它?
Error:
Assignment of string literal to variable
Run Code Online (Sandbox Code Playgroud)
如果我使用:
#define MAXSTR "Maximum number reached"
char *str = (char *) MAXSTR;
Run Code Online (Sandbox Code Playgroud)
然后lint错误:
Attempt to cast away const (or volatile)
Run Code Online (Sandbox Code Playgroud)