5
9
2014
20

restudy of c

1 include"" 和include<>区别。

  前者在当前目录下找头文件,找不到再到系统目录下找,而include<>,直接在系统目录下找。所以include""涵盖了include<>

2.incline 声明函数,表示内联函数,内联函数即在调用处直接展开函数,而并非取调用函数,故不用保存现场,效率得到提高

3 宏定义简单函数,如#define TABLE_COMP(x) ((x)>0?(x):0)

  优点:若函数调用,则要将函数的执行顺序转移到函数所存放的某个地址,将函数程序内容执行完后,在返回到转去执行原函数,故要保护现场。所以函数调用有时间、空间的开销,效率低。而宏是在预处理的地方把代码展开,五上述额外时间、空间开销。

  缺点:容易产生二义性 如TABLE_MULTI(10+10)会(10+10*10+10),而非期望的400

4.递归代码简介,但缺点(1)递归是函数调用自身,函数调用存在时间消耗:每一次函数调用,需要在内存栈中分配空间以保存参数、返回地址及临时变量,栈的压入和弹出都需要时间。故递归实现不如循环。(2)调用栈溢出。每一次调用在内存栈中分配空间,每个进程栈的容量有限,若递归调用的层级太多,就会溢出

5.计算机表示小数(float和double)都有误差,故不能直接用等号判断两个小数是否相等。如果两个小数的差值很小,比如0.0000001,就可以认为它们相等

6.取模操作 % 操作数两边都应该为整形 如 12%3 (对) 2.2%1 (错) 2%1.1(错) 2.2%1.1(错)

7 float = int/int 则除出来的数已经自动省掉了小数点后面的余数。如 f1=int1/1024,可以改为 f1=int1/1024.0

8.sleep()内的单位为秒,gcc编译,在头文件#include<unistd>中

9.若要获取运行程序进程号,linux除了通过ps指令外。还可以通过getpid函数,该函数也在unistd.h中

/*process.c*/
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include <stdio.h>
int main(int argc, char **argv)
{
 pid_t my_pid,parent_pid;
 uid_t my_uid,my_euid;
 gid_t my_gid,my_egid;
 struct passwd *my_info;
 my_pid = getpid();
 parent_pid = getppid();
 my_uid = getuid();
 my_euid = geteuid();
 my_gid = getgid();
 my_egid = getegid();
}

10 strcmp函数使用strcmp("sundayhut",myname);注意不要写成strcmp("sundayhut\n",myname);

11 sscanf用法

sscanf(temp,"%s%s%s%s%s%s%s%[^\n]",last_major_minor,last_cpu_id,last_sequence_number,last_time,last_process_id,last_action,last_RWBS,last_detail);
	

读入文件形式如下:

  8,0    0        1     0.000000000  2113  A   W 38384096 + 8 <- (8,1) 38382048
  8,1    0        2     0.000001649  2113  Q   W 38384096 + 8 [blktrace_study]
  8,1    0        3     0.000055171  2113  G   W 38384096 + 8 [blktrace_study]
  8,1    0        4     0.000234077  2113  P   N [blktrace_study]
  8,1    0        5     0.000362702  2113  I   W 38384096 + 8 [blktrace_study]
  8,1    0        0     0.000362704     0  m   N cfq640 insert_request
  8,1    0        0     0.000362705     0  m   N cfq640 add_to_rr
  8,0    0        6     0.000362707  2113  A   W 38384104 + 8 <- (8,1) 38382056
  8,1    0        7     0.000362709  2113  Q   W 38384104 + 8 [blktrace_study]

%s能自动过滤掉空格,%[^\n]可以读入行直到行尾部

 

12.若open函数用O_DIRECT方式fd=open("/home/systemtap_study/dir1/25.txt", O_RDWR | O_CREAT | O_DIRECT);

则在*.c文件中需要

#define __USE_GNU

且编译时需要加上-D_GNU_SOURCE

gcc -o out code.c -D_GNU_SOURCE

 

13.打印unsigned long

unsigned long block;

printk("new block %lu\n",block);

 

14.编译错误

编译出现如下错误

/home/tss/share/7-7/printk-pcmfs/pcmfs/pcmfs/inode.c:417: warning: ISO C90 forbids mixed declarations and code

iso c90 不允许混合使用声明和代码

解决方法是,printk语句不能再变量声明前使用

例如:void fun()

{

printf("This is a strange World!\n");

int i;

char buf[128];

}

改正方法:

void fun()

{

int i;

char buf[128];

printf("This is a strange World!\n");

}

 

Category: 未分类 | Tags: C语言 | Read Count: 1410
Avatar_small
Digital Ali 说:
2021年9月04日 20:11

This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again. soap 2 day

Avatar_small
Digital Ali 说:
2021年9月11日 15:02

Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. https://docs.google.com/spreadsheets/d/1ntiogcbDulo3Vl9Htd7Jl9Xy-2kUp7-F33vbQ4q67Uc/edit#gid=409280497

Avatar_small
jackjohnny 说:
2021年9月12日 17:05 I high appreciate this post. It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information? 온라인바둑이
Avatar_small
Digital Ali 说:
2021年9月12日 18:45

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing circularbladesaw

Avatar_small
jackjohnny 说:
2021年9月15日 17:10

I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. ไฮโลออนไลน์

Avatar_small
Gullam Mohiyoddin 说:
2021年9月28日 22:41

So part to occur over your holding tight the web diary. Your blog gets me an epic trade of overpowering.. Salubrious party covering the scene. วิธีการเล่นเสือมังกร

Avatar_small
Gullam Mohiyoddin 说:
2021年9月29日 02:58

I may propose on an immeasurably central level central paying silly going to trusted in clear pieces, later on find it: เสือมังกร ออนไลน์

Avatar_small
William 说:
2021年9月30日 16:02

I may propose on an immeasurably central level central paying silly going to trusted in clear pieces, later on find it: starvegus

Avatar_small
William 说:
2021年9月30日 20:19

In this article like the key concern, what will give you a verbalization rich framework a fundamental epic site page: บาคาร่า มือถือ

Avatar_small
William 说:
2021年10月01日 02:02

Your web diaries further more each else volume is so astonishing further key It delegates me happen for retreat go over. I will in a decreased second get your rss channel to remain worked with concerning any updates. sagaming

Avatar_small
william Johnson 说:
2021年10月02日 20:49

I truly respect this acclaimed post that you have obliged us. I ensure this would be major for a goliath piece of people. <a href="https://www.publishersmarketplace.com/dealmakers/detail.cgi?id=53704">metamorphosis literary agency</a>

Avatar_small
william Johnson 说:
2021年10月02日 20:52

I truly respect this acclaimed post that you have obliged us. I ensure this would be major for a goliath piece of people. metamorphosis literary agency

Avatar_small
William Johnson 说:
2021年10月03日 01:30

it's totally meanful. it's truly cool blog. Interfacing is key thing.you have really helped stores of people who visit blog and give them usefull information. แทงหวย

Avatar_small
Dave 说:
2021年10月06日 23:06

Great things you’ve always shared with us. Just keep writing this kind of posts.The time which was wasted in traveling for tuition now it can be used for studies.Thanks PG SLOT

Avatar_small
link 说:
2021年10月10日 21:42

Thank you for very usefull information.. North American Bancard Agent Program

Avatar_small
link 说:
2021年10月10日 21:50

You completed a few fine points there. I did a search on the subject and found nearly all persons will go along with with your blog. North American Bancard ISO Program

Avatar_small
William Johnson 说:
2021年10月22日 12:00

it's absolutely meanful. it's really cool blog. Right hand is head thing.you have really helped stores of people who visit blog and give them usefull information. 카지노사이트

Avatar_small
William Johnson 说:
2022年6月13日 14:49

In case all else a few appraisals about it and today I expected to consider it again thinking about how it is exactingly made. Zulu Trade

Avatar_small
Jaa Login 说:
2022年8月07日 16:14

The games and the referral program through Jaa Lifestyle are one simple way of earning money online. Individuals can earn extra bucks by just spending their time on Jaa Lifestyle website and get actually involves in the flow. As well there are few option such as to watch the ads, refer friends and use other options from the website which also does earn money. Jaa Login There are various ways Jaa Lifestyle provides money to individuals by just watching or using the services from it.Individuals to access Jaa Lifestyle website, they need to have got themselves register with the website through the official process. Here are the steps that you can follow to get access to Jaa Lifestyle Login ID.

Avatar_small
BSNL SIM Card 说:
2022年8月09日 19:29

Customer require BSNL SIM card for replacement, It is either for SIM lost (mobile theft) or SIM not working cases, For the first instance, nowadays, many cell phone manufacturers are offering General Insurance, but it is at the time of purchasing the new cell phone. BSNL SIM Card General insurance companies will process the claim, But it is done on submitting all the valid documents along with BSNL replacement SIM receipt from the service provider, In the second case, if the BSNL SIM card is not working means, it is due to some common issues raised in BSNL Mobile SIM card.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com