Skip to content

Instantly share code, notes, and snippets.

View ParameswaranAP's full-sized avatar
🎯
Focusing

Parameswaran AP ParameswaranAP

🎯
Focusing
View GitHub Profile
@ParameswaranAP
ParameswaranAP / virtualFunction.cpp
Created January 26, 2025 14:00
Virtual function to call same function name of multiple class member functions
#include<iostream>
typedef enum{
TYPE1READER,
TYPE2READER
}readerInfo;
class reader
{
public:
@ParameswaranAP
ParameswaranAP / assert.c
Created January 19, 2025 15:27
assert function and custom assert expression implementation using c
#include<stdio.h>
//#define NDEBUG // enable this macro to disable system default asserts not for static_asserts(use above assert.h)
#include<assert.h>
#define VALUE 0
#define ASSERT(exp)(exp ? : assertfailed(__FILE__, __LINE__, #exp))
void assertfailed(const char *filename, int line, const char *expression)
{
printf("[ERROR]: error in assert: %s, line: %d, of following exp: %s\n",filename,line,expression);
@ParameswaranAP
ParameswaranAP / concatenationOperator.c
Created July 1, 2024 06:54
concatenation operator ## usage example code in c
// Online C compiler to run C program online
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
typedef uint8_t err_ret;
void ExtFlash_init(void);
void Rtc_init(void);
@ParameswaranAP
ParameswaranAP / structInEnumBit.c
Created May 9, 2024 16:15
Using struct inside typdef union and using bit field
#include <stdio.h>
#include <stdint.h>
typedef union {
uint8_t data;
struct {
uint8_t bit0:1; //only one bit will be assigned by using ":1"
uint8_t bit1:1;
uint8_t bit2:1;
uint8_t bit3:1;
@ParameswaranAP
ParameswaranAP / CallBackFn.c
Created May 6, 2024 17:05
Callback function example with typedef and structure
#include <stdio.h>
typedef void (*callBack_t) (int);
typedef struct{
callBack_t fnToCallBck;
int statusCntrl;
}callBckParam_t;
void intrptClbckFnOne(int statusRecv){
@ParameswaranAP
ParameswaranAP / TypDefFnPtrStructCall.c
Created May 6, 2024 16:07
Call typedef function pointer by passing structure variable to function
#include <stdio.h>
#define FNCALL {30,20,&printValueB} //Assigning values to array using Macros
typedef void (*ptrFunction)(int);
typedef struct{
int inputValA;
int inputValB;
ptrFunction fnToCall;
@ParameswaranAP
ParameswaranAP / count_bits.c
Created June 24, 2023 05:25
Counts number of set bits in integer
// Online C compiler to run C program online
#include <stdio.h>
int main() {
int a = 0b0101010101110001;
int count_bits =0;
for(int i=0;i<(sizeof(int)*8);i++){
int mask = 1<<i;
if(a & mask){
count_bits = count_bits + 1;
@ParameswaranAP
ParameswaranAP / float_byte.c
Created April 18, 2023 08:25
Float to Byte conversion and visevers in c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
float byte_to_float(unsigned char *const buf){
float f;
memcpy(&f, buf, sizeof(float));
return f;
}
int main(int argc, char *argv[])
@ParameswaranAP
ParameswaranAP / Macros.c
Created April 11, 2023 02:15
C predefined Macros and C macro functions
#include <stdio.h>
#define min(a,b) ((a<b)?("less\n"):("greater\n"))
int main() {
printf(min(3,1));
printf("File :%s\n", __FILE__ );
printf("Date :%s\n", __DATE__ );
printf("Time :%s\n", __TIME__ );
printf("Line :%d\n", __LINE__ );
printf("STDC :%d\n", __STDC__ );
return 0;
@ParameswaranAP
ParameswaranAP / setbit.c
Created March 23, 2023 07:55
Set particular bit in 1 byte hex value
#include <stdio.h>
typedef unsigned char uint8_t;
uint8_t setbit(uint8_t _val,uint8_t _bit)
{
uint8_t mask = 1<<(_bit-1);
return (mask | _val);
}
int main() {
uint8_t hext_data = 0x00;