Some Tips

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Expert C programming:

Unportable Code:
1- implementation-defined— The compiler-writer chooses what happens, and has to document
it.
Example: whether the sign bit is propagated, when shifting an int right.

2- unspecified— The behavior for something correct, on which the standard does not impose
any
requirements.
Example: the order of argument evaluation.
For instance, in c(a(), b()); it is unspecified whether the function a is called before or after b. The
only guarantee is that both are called before the c function.

undefined— The behavior for something incorrect, on which the standard does not impose any
requirements. Anything is allowed to happen, from nothing, to a warning message to program
termination, to CPU meltdown, to launching nuclear missiles (assuming you have the correct
hardware option installed).
Example: what happens when a signed integer overflows.

malloc(strlen(str)); it is almost always sure to be an error,


where malloc(strlen(str)+1);

int highest = MAX (v1++, v2++);


the preprocessor will expand that to:

int highest = (v1++ > v2++ ? v1++ : v2++);

a+++b >>>>> a++ + b ; c--> 0 >>>>> c-- > 0 (greedy algorithm for tokenization in lexical
analysis stage)

Once we know how to declare a variable of a given type, it is easy to


write a cast for that type: just remove the variable name and the semicolon
from the declaration and enclose the whole thing in parentheses.
Thus, since
float (*h) ();
declares h to be a pointer to a function returning a float,
(float (*)())
is a cast to a pointer to a function returning a float.

(*(void(*) () )0) ();


typedef void (*funcptr)();
(*(funcptr)0)();

ezay t3mel fn tda55allaha indexbit w set 0 or 1 welbyte


fn tet2aked en elarray eli da5allaha fiha nums men 0 to 9 for loop wa7da
sensor eloutput bta3o crnt msh volt
assembly stack
kza mcu nafs elprocessor
temp sensor w table
compiling process

eulerian path: if all nodes are of even degree , but the start and the end are odd
eulerian tour: special case, where the starting node is also the end node , so all nodes can have
even degree

- RTOS Concepts (Scheduling techniques, Main RTOS components, semaphores, critical


sections, priority inheritance, priority inversion)
- Unions Vs Structs
- Little Endian Vs Big Endian
- char[] vs char*
- Draw a Star with 3 different methods, Circle, Triangle and different shapes
- Fibonachi series using recusrive method and loop method
- Recursion effects on memory
- Pointer to functions
- triagonometric functions implementation
- Constant Pointer vs Pointer to const
- Macros vs Function, Swap macro
- Sorting algorithms
- memcpy
- UART/USART
- SPI
- I2C
- Input Capture Unit
- pre-processors like #include #define #ifdef #ifndef #pragma #asm
- Memory alighment and memory padding
- Memory segments (.data, .bss ....)
- Inturrupts, Timers, Interrupt Vector table
- CAN protocol, LIN protocol
- Products from Valeo

Ekteb function bta5od raqam w btreturn 3adad el ones eli flraqam da


Y3ni lw meda55al 5
El 5 di y3ni 101 binary
Elfunction hat return 2
Question 2:
3ndak unsorted array of 50 elements ranges from 0 to 50 , momken yb2a fiha arqam metkarrara
3adi
Ekteb function tesheel elarqam elmetkarrara di

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

void time_fun(void );
void int_prom(void );
int int_sum(int , int );
void swap_func(int ,int);
void set_bit( int );
void reset_bit(int );
int main()
{
reset_bit(3);
return 0;
}

void time_fun(void )
{
time_t max_time = INT_MAX;
time_t current_time, diff_time;
char * current, *maximum, *diff;

current_time = time(NULL);
current = ctime((const time_t *)&current_time);
printf("current time is %s\n",current);

maximum = ctime((const time_t *)&max_time);


printf("maximum time is %s\n",maximum);

diff_time = difftime(max_time, current_time);


diff = ctime((const time_t *)&diff_time);
printf("difference time is %s\n",diff);
}
void int_prom(void )
{
unsigned x = 5;
signed y = -1;
if ( y < x )
{
printf("Integer Promoted");
}
else printf("none");
}

int int_sum(int a, int b)


{
return a+b;
}

void set_bit(int bit_loc)


{
int x = 8;
x |= (1<<bit_loc);
printf("%d",x);
}

void reset_bit(int bit_loc)


{
int x = 8;
x &= ~(1<<bit_loc);
printf("%d",x);
}

typedef enum STATE_t


{
OFF,
PAUSE,
PLAY,
STOP
};

STATE_t mp3_state = OFF;

You might also like