[gcc][AVR] attributeによるバイト数装飾

2010/03/11開発環境::gccimport

変数のビットサイズ~gcc方言の巻

avr-gccのstdint.hを見る

VMにWinXP32bitを放り込んで、WinAVR 20100110をインスコ。uint32_tが8bitになっとる、という話をmixiのコミュで見かけたので検証してみました。とりあえずコードレベルで追いかけるとして、ヘッダファイルを探索。

typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__))); 

・・・・なんぞこれ。

__attribute__ってあたりは、まぁ、なんぞローカル定義の装飾しているなぁとは思うわけですが、__SI__ってなによ...


変数サイズ指定

Anton-sanがいいこといった! Single Integerだそうだ。

・・・ナニソレ?


* Title: Gcc help pages about __mode__ keyword
* From: Anton Soppelsa <soppelsa at igi dot cnr dot it>
* To: gcc at gnu dot org
* Date: Tue, 22 Nov 2005 15:48:45 +0100
* Subject: Gcc help pages about __mode__ keyword

Dear GCC help pages maintainers,
I recently encountered a statement like this one


__attribute__((__mode__(__DI__)))

in a micro kernel source file.

As I'm not so skilled with this kind of C/C++ syntax I tried to read the manual about the keywords involved in that expression.
Despite I found information about "__attribute__" and "__mode__"
I wasn't able to find information about "__DI__" (on the gcc manual pages).
Of course I found in Internet partial explanation of the meaning of "__DI__" keyword and also found out that there are many of the same type like "__SI__", "__HI__", and "__QI__".
 By the way, do they mean Double-, Single-, Half-, Quarter-, -Integer?

The point is that it seem to me those identifiers are actually keywords of the compiler.
So they really have be mentioned (at least) in the compiler manual. Better would be if they are explained.
I guess that part of the manual is not so well maintained because I found only reference to the keywords "__byte__" or "__word__" or "__pointer__".


This message is just to inform u about something if u have the time to work about has to be done (in my opinion) .
Best regards,

※本文にメールアドレスがありましたが、削除しています。改行も入れました..

__SI__の謎

George-sanないすだ!CIL (C Intermediate Language)ということで、Cコンパイル時の中間言語の領域に到達した。やはりこのあたりから学ばないと、コンパイラの理解は終わらないようだな…。


GCC allows you to use the __mode__ attribute to specify the size of the integer instead of the standard char, short and so on:

int __attribute__ ((__mode__ (  __QI__ ))) i8;
int __attribute__ ((__mode__ (  __HI__ ))) i16;
int __attribute__ ((__mode__ (  __SI__ ))) i32;
int __attribute__ ((__mode__ (  __DI__ ))) i64;

ちょっとわかりづらい。CLI特有というわけでもないぽいなぁ...


答えは身近に―

後閑師のところで、C30の説明があり、ここで紹介されてました。ナンテコッタイw

以下、引用

typedef int __attribute__((__mode__(SI))) int32 ; // int32を32ビット幅の整数型と定義

modeで指定したビット幅の型を定義する\byteは1バイト整数型、wordは1ワード整数、pointerはポインタ型を定義する\modeには下記記号が使用できる\QI : 8ビット(char)\HI : 16ビット(int)\SI : 32ビット(long)\DI : 64ビット(long long)\SF : 32ビット(float)\DF : 64ビット(long double)ちょっぴり、アンダースコアの量が違いますが、まぁ、もともとも思想は同じと思って良いでしょう。処理系依存が多いでしょうし、迷ったときはアセンブラコードをはかせてみる。sizeof()でバイト数をチェックする、といった習慣をつけたほうが良いですね。特にマイコン屋さんは。仕事でも趣味でも。ね。。

注意

斜め読みどころか、英語弱いのにかじりながら見た部分が多いですので、鵜呑みにせずリンク先の情報を消化して納得してください。\WEBの情報がすべて正しいとは限りませんし、何事も本家までさかのぼるよう習慣付けましょう…。頼むよほんと(ぉ