MISRA-C diary(C言語日誌)

2018年6月の記事一覧

C++ Template technique

C++ Template technique

C++Standard Committee papers
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/

standard C++
http://isocpp.org

Collected papers of Alexander A.Stepanov
http://www.stepanovpapers.com

cpprefjp
http://sites.google.com/site/cpprefjp/
boostjp
http;//sites.google.com/site/boostjp


C++テンプレート完全ガイド

 Modern C++ Design

C++テンプレートメタプログラミング


ジェネレーてぃぶプログラミング

C++設計と進化


Boost C++ Libraries
0

「組み込み系」「エンタープライズ系」は死語か。"freestanding", "hosted"は生き残るか。

一昔前、「組み込み系」「エンタープライズ系」という言葉が流行った。

「経済産業省が、「組み込み系」に力を入れる」という話があったらしい。
猫も杓子も「組み込み系」に力を入れるようになったらしい。

しかし、誰に聞いても「組み込み系」「エンタープライズ系」の区分の答えは曖昧。

その後、IoT(internet of things)という言葉が流行り、
猫も杓子もIoTに。

また、深層学習(DeepLearning)が実用的になり、
IoTで集めたデータを機械学習で利用することも流行っている。

ここで、「組み込み系」「エンタープライズ系」という定義がわからない言葉から離れて、C言語、C++の言語規格で規定している"freestanding", "hosted"という区分で考えてみる。
0

フリースタンディング環境(C言語)TOPPERS/SSP

C言語規格には、
Freestanding
Hosted
の2つの環境がある。

Hostedは、OSがC言語の未規定の動作のうち、どちらを取るかを

3.1にfreestandingの記述あり
「The compiler selected for the project should meet the requirements of a conforming freestanding implementation for the chose version of the C language.」
shallではないので、hostでも良いと読める。
掲示板で質問。

Dir1.1 freestandingの記述あり。

課題は、設計作業環境はhost環境で、設計対象がfreestandingの場合に、host環境とfreestanding環境の違いがわかっていないと、話が乱れる。

C99では、__STDC_HOSTED_ _が1ならhost、そうでなければfreestanding。

freestandingの場合
1 start-upがmainかそうでないか、および型
2 library 関数(最小以外)
3 終了処理
4 size_t, wchar_tなどのすべての型を用意しなくてもよい。(C99 7.18.3)
がimplementation definition。

freestandingでimplementation definition を確認した時点で、
関係なくなるルールがあるかどうかの検討が済んでないかも。

freestandingの場合でも定義するヘッダファイル(C90とC99共通とC99のみ有)

#include <float.h>
#include <iso646.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#ifdef __STDC_VERSION__
#include <stdalign.h>
#include <stdnoreturn.h>
#endif 

NULLを規定しているstdlib.hはfreestandingでは必須でない。
標準、入出力stdio.h, 文字列のstring.hも必須ではない。
これらの利用を前提としている規則では、freestandingでは、必ずしも必須でないことについての言及があるとよい。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

ps.
http://www.misra.org.uk/forum/viewtopic.php?f=225&t=1485
In example codes in Rule 11.1 and Rule 11.2

#include <stdlib.h> /* to obtain macro NULL */

in example codes in 11.9

#include <stddef.h>

A freestanding environment needs stdarg.h not sodlib.h.
So I prefer to obtain macro NULL, 
#include <stddef.h> // to obtain macro NULL

Is it reasonable?

ps. in 11.9 
/* Could also be stdio.h, stdlib.h and others */

I prefer
/* A free standing environments needs stddef.h */
/* Could also be stdio.h, stdlib.h and others in host environments */

Best Regards.
Dr. Kiyoshi Ogawa 
0

C++マクロからtemplateへ

##1
マクロVSテンプレート
https://project-flora.net/2013/09/18/マクロvsテンプレート/

```c++:macro.cpp
#define MULTIPLY(a,b) (a)*(b)
```
上記マクロは下記

```c++:template.cpp
template<typename T> T multiply(T a, T b) {
return a * b;
}

int val = multiply<int>(10 * 20);
```
##2
マクロ関数よりもテンプレート関数
http://d.hatena.ne.jp/pknight/20090805/1249462821

#define MACRO_MAX(a,b) ((a)>(b)?(a):(b))

// テンプレート&インラインでのmax関数
template <class T> inline T template_max(const T& a,const T& b) {
    return a > b ? a : b;
}

##3 特注の鋳型
http://www7b.biglobe.ne.jp/~robe/cpphtml/html02/cpp02036.html




###4 
よく使って来たマクロ

```
#define  PR1x(a,b) (void)printf(" "#a  " = %" #b "=%x\n", a,a)
```

```
template<type T> T void pr(T a,T b) {
cout << (b)
}

0

構造体入門

構造体入門

C言語

構造体選択演算子

1.
構造体メンバーのアクセス
http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate4/JA/html/devwin32/structurememberaccess_xml.html
選択演算子
. (ピリオド)
->(右矢印)

2.
構造体メンバへのアクセス方法
http://www.ie.u-ryukyu.ac.jp/~e075769/study/study/c/ch8/8_2.php

構造体メンバ演算子(structure member operator)
ドット( . )

3.
構造体
http://www.cc.kyoto-su.ac.jp/~yamada/programming/struct.html

メンバ参照(間接参照)
参照するための演算子 "->"

0

プログラマのプログラマによるプログラマ同士の意思疎通のためのプログラミング言語の定義(意味論)

プログラマのプログラマによるプログラマ同士の意思疎通のためのプログラミング言語の定義(意味論)

For the programmer's, by the programmer's and/or of the programmer's programming language definition for the communication, not syntax, but semantics.

  1. psittacism

psittacism is to return the words of the speaker as it is.

  1. Question 2.1 

2.2 5W1H
2.2.1 What

Question about what it is.

2.2 Who

Question about identification of people.

3.


0

C++ in depth series

A Tour of C++, 2nd Edition
By Bjarne Stroustrup
eBook (Watermarked)  $25.59
A Tour of C++, 2nd Edition
A Tour of C++, 2nd Edition
By Bjarne Stroustrup
Book  $31.99
Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers
Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers
By Peter Gottschling
Book  $39.99
Tour of C++, A
Tour of C++, A
By Bjarne Stroustrup
Book  $27.99
C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond
C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond
By David Abrahams, Aleksey Gurtovoy
Book  $47.99
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices
By Herb Sutter, Andrei Alexandrescu
Book  $47.99
Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions
Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions
By Herb Sutter
Book  $39.99
C++ Network Programming, Volume 2: Systematic Reuse with ACE and Frameworks
C++ Network Programming, Volume 2: Systematic Reuse with ACE and Frameworks
By Douglas Schmidt, Stephen D. Huston
Book  $51.99
C++ Network Programming, Volume I: Mastering Complexity with ACE and Patterns
C++ Network Programming, Volume I: Mastering Complexity with ACE and Patterns
By Douglas Schmidt, Stephen D. Huston
Book  $47.99
Modern C++ Design: Generic Programming and Design Patterns Applied
Modern C++ Design: Generic Programming and Design Patterns Applied
By Andrei Alexandrescu
Book  $51.99

Accelerated C++: Practical Programming by Example
By Andrew Koenig, Barbara E. Moo
Book  $39.99
Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions
Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions
By Herb Sutter
Book  $43.99
Essential C++
Essential C++
By Stanley B. Lippman
Book  $39.99

0