The Standard C Library for Linux

2016-02-19 12:40 4 1 收藏

岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的The Standard C Library for Linux,希望大家看完后能赶快学习起来。

【 tulaoshi.com - 编程语言 】


  Part Six: assert.h Diagnostics for Programmers
  By James M. Rogers
  
  --------------------------------------------------------------------------------
  
  The last article was on stdlib.h Standard Library. This article is on assert.h Diagnostics for Programmers.
  
  I am assuming a knowledge of c programming on the part of the reader. There is no guarantee of accuracy in any of this information nor suitability for any purpose.
  
  If used properly assertions will allow programmers to mUCh more easily document and debug your code with no impact on runtime performance. Assertions are not meant to be used for production code as they cause the program to terminate with an error condition. Since assertions are never to be used in production code they are not useful in finding runtime errors such as a failure to allocate memory. You must still handle failed return conditions of all function calls the same as always.
  
  Instead, what assertions allow you to do is document the assumptions that you make as you program and allow you to debug the obvious logic errors that you have made. As you program around these logic errors you can modify your assertions to not die on errors that you are now handling.
  
  The example is rogers_example06.c :
  
  #include stdio.h
  #include assert.h
  
  /*
  
  This program is written to demonstrate the stdlib.h library.
  
  This program will demonstrate the assert function
  
  Written by James M. Rogers
  
  12 April 1999
  
  Released to the Public Domain on this date.
  
  */
  
  /*
  
  Compile this with the -DNDEBUG flag in order to _NOT_
  
  compile the assert statement.
  
  So all production boxes should compile with the -DNDEBUG flag.
  
  */
  
  main (){
  
  int i=1;
  int j=0;
  assert(j!=0);
  printf("%s", i/j);
  }
  
  In this program I will demonstrate the use of assertions by using a simple program that asks for two numbers and then divides the first number by the second. Compile the program with the following:
  
  gcc -DNDEBUG rogers_example06.c -o assert
  
  and then run ./assert and try to divide by zero. The flag -NDEBUG will cause your assertion to generate no runtime code. This flag should be used in all production environements
  
  Your program will core dump with almost no indication of the problem. Now recompile the program with the following:
  
  
  gcc rogers_example06.c -o assert
  
  Now run the program again and again try to divide by zero. This time it should be much more apparrent what the problem is and very easy to locate the exact line that had the problem.
  
  As always, if you see an error in my documentation please tell me and I will correct myself in a later document. See corrections at end of the document to review corrections to the previous articles.
  
  Assertions
  
  #include assert.h
  void assert(int eXPression);
  
  From:www.Linuxgazette.com

来源:http://www.tulaoshi.com/n/20160219/1601504.html

延伸阅读
  文/余海发     本文介绍了Linux的C开发环境的构成和安装,使读者对Linux的C开发环境能有初步的了解。 你了解Linux吗?相信现在越来越多的人会说“是”的。那么你了解到何种程度呢?不可否认,目前决大多数的Linux用户对Linux的了解还处于比较低级的层次,他们可能会几条命令、会配几种服务、会用rpm来安装软...
getenv(取得环境变量内容) 相关函数 putenv,setenv,unsetenv表头文件 #include 定义函数 char * getenv(const char *name);函数说明 getenv()用来取得参数name环境变量的内容。参数name为环境变量的名称,如果该变量存在则会返回指向该内容的指针。环境变量的格式为name=value。返回值 执行成功则返回指向该内容的指针,找不到符合的环境...
标签: Web开发
使用库元素必须首先在DW中正确建立站点。 库被设计用来使重复性的工作更快、更容易并尽可能地无差错。 任何网页中的元素,无论文本还是图形均可以指定为库元素。 库元素可以用来放置在同一个站点内的任何页面中,而不需要重新输入文本或插入图片等。 可以在任何时候修改库文件。编辑完成,保存,DW会同时更新所有应用...
DataOleDb Data Provider for Enterprise Library 1.0This is a first attempt at the necessary OleDb classes for Enterprise Library 1.0. It consists of an OleDbDatabase class, an OleDbCommandWrapper class, and numerous test fixtures.Sybase ASE Data ProviderThis Enterprise Library extension uses the Sybase ASE .NET Data Pr...
处理 C++ 中的异常会在语言级别上碰到少许隐含限制,但在某些情况下,您可以绕过它们。学习各种利用异常的方法,您就可以生产更可靠的应用程序。保留异常

经验教程

784

收藏

28
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部