スレッド: [cppll:9310] Re: ポインタのサイズ

スレッド

[cppll:9310] Re: ポインタのサイズ

[ | ▲ / | ]
Subject:
[cppll:9310] Re: ポインタのサイズ
From:
takayuki.ebiko‐at‐nts.ricoh.co.jp <takayuki.ebiko@...>
Date:
Thu, 7 Aug 2003 10:16:53 +0900
X-Mailer:
Lotus Notes Release 5.0.2b 28 December 1999
Message-Id:
<OFAABF5426.C4D5C209-ON49256D7B.0006334D‐at‐nts.ricoh.co.jp>
思いっきり説明べたですいません。

sizeof char*
sizeof double*
sizeof XXX*
が同じだというのはどこかで保証されてるのかなと。

保証されてなきゃ
Base* = new Derived();
なんてこと出来ないから、どこかに書かれてるんでしょうけど・・・

[cppll:9311] Re: ポインタのサイズ

[ | / | ]
Subject:
[cppll:9311] Re: ポインタのサイズ
From:
FUKUDA Fumiki <fukuda.fm@...>
Date:
Thu, 07 Aug 2003 10:25:00 +0900
X-Mailer:
WeMail32[1.42] ID:NTES00
Message-Id:
<200308070132.h771WEr14288‐at‐mailsv4.nec.co.jp>
In-Reply-To:
9310
επιστημηです。

--- "[cppll:9310] Re:  ポインタのサイズ" / takayuki.ebiko@... ---

>sizeof char*
>sizeof double*
>sizeof XXX*
>が同じだというのはどこかで保証されてるのかなと。

同じと考えていいと思う。

けど、それが保証されていれば、なぜにして

複数モジュールでコンパイル時の依存をなくすために、
よくポインタを用いたりしています。

なのかがわかんないのです。

-----:-----:-----:-----:-----:-----:-----:-----:-----:-----
FUKUDA (episteme) Fumiki -- magical, but never a magic...

[cppll:9313] Re: ポインタのサイズ

[ | / | ]
Subject:
[cppll:9313] Re: ポインタのサイズ
From:
FUKUDA Fumiki <fukuda.fm@...>
Date:
Thu, 07 Aug 2003 10:33:52 +0900
X-Mailer:
WeMail32[1.42] ID:NTES00
Message-Id:
<200308070141.h771f9S20305‐at‐mailsv.nec.co.jp>
In-Reply-To:
9310
επιστημηです。

--- "[cppll:9310] Re:  ポインタのサイズ" / takayuki.ebiko@... ---

>sizeof char*
>sizeof double*
>sizeof XXX*
>が同じだというのはどこかで保証されてるのかなと。
>
>保証されてなきゃ

どれも malloc 一個でまかなえるワケないですなぁ。

-----:-----:-----:-----:-----:-----:-----:-----:-----:-----
FUKUDA (episteme) Fumiki -- magical, but never a magic...

[cppll:9314] Re: ポインタのサイズ

[ | / | ]
Subject:
[cppll:9314] Re: ポインタのサイズ
From:
KOIE Hidetaka <hide@...>
Date:
Thu, 07 Aug 2003 10:58:22 +0900 (JST)
X-Mailer:
Mew version 4.0.58 on Emacs 21.1 / Mule 5.0 (SAKAKI)
Message-Id:
<20030807.105822.26984817.hide‐at‐koie.org>
In-Reply-To:
9313
References:
9310 9313
Message-Id: <200308070141.h771f9S20305@mailsv.nec.co.jp>
 Date:       Thu, 07 Aug 2003 10:33:52 +0900
 From:       FUKUDA Fumiki <fukuda.fm@...>
 Subject:    [cppll:9313] Re: ポインタのサイズ

 | επιστημηです。
 |
 | --- "[cppll:9310] Re:  ポインタのサイズ" / takayuki.ebiko@... ---
 |
 | >sizeof char*
 | >sizeof double*
 | >sizeof XXX*
 | >が同じだというのはどこかで保証されてるのかなと。
 | >
 | >保証されてなきゃ
 |
 | どれも malloc 一個でまかなえるワケないですなぁ。

mallocはvoid*なのでまかなえる、ですよね。

ARMのどこかに、ワードアドレッシングのマシンだと
 sizeof (int*) < sizeof (char*) == sizeof (void*)
となる、という話があったとおもいます。

--
鯉江英隆 <hide@...>

[cppll:9315] Re: ポインタのサイズ

[ | / | ]
Subject:
[cppll:9315] Re: ポインタのサイズ
From:
T.Sawamoto <sawamoto@...>
Date:
Thu, 07 Aug 2003 11:10:06 +0900
X-Mailer:
Becky! ver. 2.05.11
Message-Id:
<20030807110008.175D.SAWAMOTO‐at‐deneb.freemail.ne.jp>
In-Reply-To:
9313
References:
9310 9313
さあもとです。

[cppll:9313] FUKUDA Fumiki wrote:
> >保証されてなきゃ
>
> どれも malloc 一個でまかなえるワケないですなぁ。

farmalloc…。(ガクガクブルブル)

関数ポインタとデータポインタでサイズが異なる、というのはあり
得ることだと思います。
例えばXXXが

typedef void (XXX)(void);

のように定義されているばやい、とか。

〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
 へ  へ    さあもと
 の  の    E-Mail : sawamoto@...
〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜

[cppll:9316] Re: ポインタのサイズ

[ | / | ]
Subject:
[cppll:9316] Re: ポインタのサイズ
From:
Satoshi Nakamura <watson@...>
Date:
Wed, 06 Aug 2003 19:26:06 -0700
X-Mailer:
QMAIL 2.9.2 / Windows 2000 Service Pack 4 / x86
Message-Id:
<297220030806191616watson‐at‐zak.att.ne.jp>
In-Reply-To:
9310
References:
9310
中村です。

At 07 Aug 2003 10:16:53 +0900 takayuki.ebiko@... wrote:
> sizeof char*
> sizeof double*
> sizeof XXX*
> が同じだというのはどこかで保証されてるのかなと。
>
> 保証されてなきゃ
> Base* = new Derived();
> なんてこと出来ないから、どこかに書かれてるんでしょうけど・・・

ポインタのサイズが違っても上記のことは出来ます。

Base* p = new Derived();

はDerivedへのポインタをBaseへのポインタに変換するという意味であって、物理
的にポインタの値をコピーすることを意味するわけではありません。ですから、コ
ンパイラが然るべきコードを生成すればポインタのサイズが異なっても上記のこと
は達成できます。

ポインタの物理的な表現方法について述べてあるのは、ISの3.9.2の3と4でしょうか。

> 3 A pointer to objects of type T is referred to as a “pointer to T.”
> [Example: a pointer to an object of type int is referred to as “pointer
> to int” and a pointer to an object of class X is called a “pointer to
> X.” ] Except for pointers to static members, text referring to “
> pointers” does not apply to pointers to members. Pointers to incomplete
> types are allowed although there are restrictions on what can be done
> with them (3.9). The value representation of pointer types is
> implementation defined. Pointers to cv-qualified and cv-unqualified
> versions (3.9.3) of layoutcompatible types shall have the same value
> representation and alignment requirements (3.9).
>
> 4 Objects of cv-qualified (3.9.3) or cv-unqualified type void* (pointer to
> void), can be used to point to objects of unknown type. A void* shall be
> able to hold any object pointer. A cvqualified or cvunqualified (3.9.3)
> void* shall have the same representation and alignment requirements as a
> cv-qualified or cv-unqualified char*.


ISの引用部分では除外されていますが、メンバ関数へのポインタなんかはサイズが
異なることが殆どではないかと思います。


ところで、実際にvoid*とint*のサイズが違うようなシステムってどんなものがあ
るのでしょう?

--
Satoshi Nakamura <snak@...>

[cppll:9318] Re: ポインタのサイズ

[ | / ▼ | ]
9318
Subject:
[cppll:9318] Re: ポインタのサイズ
From:
Tietew <tietew@...>
Date:
Thu, 07 Aug 2003 12:54:25 +0900
X-Mailer:
Becky! ver. 2.06
Message-Id:
<20030807125135.70C2.TIETEW‐at‐tietew.net>
In-Reply-To:
9310
References:
9310
Tietew です。

On Thu, 7 Aug 2003 10:16:53 +0900
In article <OFAABF5426.C4D5C209-ON49256D7B.0006334D@nts.ricoh.co.jp>
[[cppll:9310] Re:  ポインタのサイズ]
takayuki.ebiko@... wrote:

> sizeof char*
> sizeof double*
> sizeof XXX*
> が同じだというのはどこかで保証されてるのかなと。

保証されてはいません。

> 保証されてなきゃ
> Base* = new Derived();
> なんてこと出来ないから、

いいえ。もしサイズが違ってもコンパイラが補正してくれます。

NULL は 0 と可換だけどメモリ上でゼロ値とは限らないのと似てるかな。


—[ Tietew ]——— tietew@... / tietew@... ——————
■Tietew Windows Lab.                        http://www.tietew.net/
★C++:language&libraries過去ログ&なまず http://www.tietew.jp/cppll/
PGP fingerprint: 26CB 71BB B595 09C4 0153  81C4 773C 963A D51B 8CAA

Navigation

検索

[検索ヘルプ]

Maintener: Tietew <www.tietew.jp>
Powered by Ruby on Rails, Mongrel, PostgreSQL, and Hyper Estraier.
click here