当前位置:网站首页>Analysis and implementation of variable parameters in C language
Analysis and implementation of variable parameters in C language
2022-06-13 09:39:00 【LuckyDog0623】


#include <stdio.h>
#include <stdarg.h>
struct person{
char *name;
int age;
char score;
};
struct person1{
char *name;
int age;
char score;
}__attribute__((packed));
struct person2{
char *name;
int age;
char score;
}__attribute__((aligned(4)));
/* int printf(const char *format, ...); */
int push_test(const char *format,...)
{
//char *p=(char *)&format;
va_list p;
int i;
struct person per;
char c;
double d;// Defined as float Will fail , Because floating point numbers default to double Type passing
printf("arg1: %s\n",format);
//====================================
//p = p + sizeof(char *);// Why is this place char*
va_start(p,format);
//i=*((int *)p);
i=va_arg(p,int);
printf("arg2:%d\n",i);
//=====================================
//p=p+sizeof(int);
//per=*((struct person*)p);
per=va_arg(p,struct person);
printf("arg3:.name=%s,.age=%d,.score=%c\n",per.name,per.age,per.score);
//=======================================
//p=p+sizeof(struct person);
//c=*((char *)p);
c=va_arg(p,int);
printf("arg4:%c\n",c);
//======================================== Note that the stack also holds 4 Byte alignment
//p=p+(sizeof(char) +3);// p=p+((sizeof(char) +3)& ~3);
//d=*((double *)p);
d=va_arg(p,double);
va_end(p);
printf("arg5:%f\n",d);
return 0;
}
int main(int arhgc, char **argv)
{
struct person per={"tangjun",100,'B'};
printf("sizeof(char )=%d\n", sizeof(char ));
printf("sizeof(int )=%d\n", sizeof(int ));
printf("sizeof(char* )=%d\n", sizeof(char * ));
printf("sizeof(char** )=%d\n", sizeof(char** ));
printf("sizeof(struct person )=%d\n", sizeof(struct person));
printf("sizeof(struct person1)=%d\n", sizeof(struct person1));
printf("sizeof(struct person2)=%d\n", sizeof(struct person2));
push_test("abcd",123, per,'c',2.79);
return 0;
}#include <stdio.h>
struct person{
char *name;
int age;
char score;
};
struct person1{
char *name;
int age;
char score;
}__attribute__((packed));
struct person2{
char *name;
int age;
char score;
}__attribute__((aligned(4)));
/* int printf(const char *format, ...); */
int push_test(const char *format,...)
{
char *p=(char *)&format;
int i;
struct person per;
char c;
double d;// Defined as float Will fail , Because floating point numbers default to double Type passing
printf("arg1: %s\n",format);
//====================================
p = p + sizeof(char *);// Why is this place char*
i=*((int *)p);
printf("arg2:%d\n",i);
//=====================================
p=p+sizeof(int);
per=*((struct person*)p);
printf("arg3:.name=%s,.age=%d,.score=%c\n",per.name,per.age,per.score);
//=======================================
p=p+sizeof(struct person);
c=*((char *)p);
printf("arg4:%c\n",c);
//======================================== Note that the stack also holds 4 Byte alignment
p=p+(sizeof(char) +3);// p=p+((sizeof(char) +3)& ~3);
d=*((double *)p);
printf("arg5:%f\n",d);
return 0;
}
int main(int arhgc, char **argv)
{
struct person per={"tangjun",100,'B'};
printf("sizeof(char )=%d\n", sizeof(char ));
printf("sizeof(int )=%d\n", sizeof(int ));
printf("sizeof(char* )=%d\n", sizeof(char * ));
printf("sizeof(char** )=%d\n", sizeof(char** ));
printf("sizeof(struct person )=%d\n", sizeof(struct person));
printf("sizeof(struct person1)=%d\n", sizeof(struct person1));
printf("sizeof(struct person2)=%d\n", sizeof(struct person2));
push_test("abcd",123, per,'c',2.79);
return 0;
}边栏推荐
- LeetCode 202. Happy number
- 【pytorch环境安装搭建】
- [51nod p2106] an odd number of times [bit operation]
- [Luogu p1090, ssl1040] merged fruit [pile]
- 【工具链系列】 Notepad++
- UNIX Environment advanced programming --3-file io---3.10 file sharing
- Classes and objects -- encapsulation
- [51nod p3395] n-bit gray code [bit operation]
- Calculate the number of days between two times (supports cross month and cross year)
- I have summarized the knowledge points of JS [intermediate and advanced] for you
猜你喜欢

(dfs) acwing 842. Arrange numbers

Trees and binary trees: Construction of binary trees

简述请求过程

C language: five custom types

Exercise 7-10 finding specified characters (15 points)

阿里高级专家剖析 | Protocol的标准设计

It was so simple to implement system call

Trees and binary trees: traversal of binary trees

Tree and binary tree: application of binary tree traversal

Classes and objects -- object model and this pointer
随机推荐
C language: file operation
Consolas-with-Yahei
C language structure
隐私计算FATE-核心概念与单机部署
Class template
Timestamp to localdate
Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?
go-zero微服务实战系列(三、API定义和表结构设计)
删除软链接
Figure: concept of figure
C language: dynamic memory management
Remember! Don't be too confident in writing code! Be sure to write some key log info output, or the problem will not be located.
Summary of random number learning
(dp+ memory) acwing 901 skiing
VDD,DVDD,AVDD,VCC,AFVDD,DOVDD,IOVDD
Exploitation of competitive loopholes in attacking and defending world PWN play conditions
LeetCode 6096. Success logarithm of spells and potions (binary search)
[implementation of depth first search]
[51nod p2106] an odd number of times [bit operation]
LeetCode 1. Sum of two numbers