[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] a few things
- From: "Schleimer, Ben" <bensch128@xxxxxxxxx>
- Date: Thu, 10 Jan 2008 11:44:46 -0800 (PST)
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=WDSE7JBETc5eG4sj+4v/N2MdWRBfjaWaT58RzAvT39geHCU4srxXOdq9U5xZyjhlc1/yCqY9p82oqOX4cI61RP/l80TCaC8+wggE8F2LG35Lci0epHYot/ecBeZ3MmtGdF6xD1mNAUjdYV27K64bNPs0YtweVzq96AsT8MtDhao=;
> My concern here is the following. Suppose that at some point during
> compilation, the compiler has decided that the underlying integer type
> for "enum Size" is "char" (this counts as an integer type, right?)
>
> Suppose then (unlikely but possible) that later the compiler finds in the
> source code an instanciation like
>
> Matrix<float, 128, 1> myBigFixedSizeVector;
>
> 128 doesn't fit into char so what happens?
> - compiler error?
> - integer overflow / undefined behavior?
> - or is the compiler so clever that it will first go through the whole source
> code to see what integer type is really needed?
>
> (Well I ask about the compiler but what I really care about is the C++
> standard i.e. I don't want to use non-standard behavior)
>
> Is it a good idea, to work around this issue, to declare enum Size as follows?
> enum Size { Dynamic = -1, Generic = -2, Dummy = INT_MAX };
> in order to ensure that the underlying type is "int" ?
I don't know about the rest of the questions but
stroustrup agrees with you here. Section 4.8.
I think you'll be safe anyway because there is always an implicit conversion operator from enum to
int. I think your template arguments have to be int so everything should be ok.
Cheers
Ben