写点什么

Programming abstractions in C 阅读笔记 p111-p113: boilerplate

作者:codists
  • 2023-08-15
    广东
  • 本文字数:1736 字

    阅读完需:约 6 分钟

《Programming Abstractions In C》学习第 47 天,p111-p113,总结如下:


一、技术总结 1.boilerplate


/* * File: random.h * Version: 1.0 * Last modified on Fri Jul 22 16:44:36 1994 by eroberts * ----------------------------------------------------- * This interface provides several functions for generating * pseudo-random numbers. */
#ifndef _random_h#define _random_h
#include "genlib.h"#include <stdlib.h>
/* * Constant: RAND_MAX * ------------------ * Unfortunately, several libraries that supposedly conform to * the ANSI standard do not define RAND_MAX in <stdlib.h>. To * reduce portability problems, this interface defines RAND_MAX * to be the largest positive integer if it is undefined. */
#ifndef RAND_MAX# define RAND_MAX ((int) ((unsigned) ~0 >> 1))#endif
/* * Function: Randomize * Usage: Randomize(); * ------------------- * This function sets the random seed so that the random sequence * is unpredictable. During the debugging phase, it is best not * to call this function, so that program behavior is repeatable. */
void Randomize(void);
/* * Function: RandomInteger * Usage: n = RandomInteger(low, high); * ------------------------------------ * This function returns a random integer in the range low to high, * inclusive. */
int RandomInteger(int low, int high);
/* * Function: RandomReal * Usage: d = RandomReal(low, high); * --------------------------------- * This function returns a random real number in the half-open * interval [low .. high), meaning that the result is always * greater than or equal to low but strictly less than high. */
double RandomReal(double low, double high);
/* * Function: RandomChance * Usage: if (RandomChance(p)) . . . * --------------------------------- * The RandomChance function returns TRUE with the probability * indicated by p, which should be a floating-point number between * 0 (meaning never) and 1 (meaning always). For example, calling * RandomChance(.30) returns TRUE 30 percent of the time. */
bool RandomChance(double p);
#endif
复制代码


p113,These three lines are often referred to as interface boilerplate。boilerplate 这个词会在计算机相关的教材中会经常看到,英文的意思是:“text that can be copied and used in computer program,with only small changes.”(模板),之所以叫模板,是因为在每个头文件中都有这三句。这个单词不难理解,关键是通过此次的教材对这个单词有一个具体的、形象的记录,当提到这个单词,就知道具体指的是什么。


二、英语总结


1.roll a die 一句里面的 die 是什么意思?答:die: n.a small cube with a different number of spots on each side.(骰子),所以 roll a die 的就是"掷骰子"。


2.along with 语法

答:along with 在表示伴随、以及或连同等意思时,两者之间无先后顺序,可能在前也可能在后。这点与 follow 不同。示例:For each of these functions, the interface contains one-line prototype along with a comment that describe the purpose of the function from the perspective of clients.


3.up to 语法答:原文:The line:


#ifndef _random_h
复制代码


cause the compiler to skip any text up to the #endif line if the the symbol _random_h has been previously defined。

up to 短语主要有两种用法:

(1)adv. used to say that sth is less than or equal to but not more than a stated value。

(2)adv. until。

都表示的是“程度”,而不是“方向”。


三、参考资料

1.编程

1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414

2.英语

1)Etymology Dictionary:https://www.etymonline.com

2)Cambridage Dictionary:https://dictionary.cambridge.org


欢迎搜索及关注:编程人(a_codists)

发布于: 刚刚阅读数: 3
用户头像

codists

关注

公众号:编程人 2021-01-14 加入

Life is short, You need Python

评论

发布
暂无评论
Programming abstractions in C阅读笔记p111-p113: boilerplate_codists_InfoQ写作社区