You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Torbjörn Bäckström <to...@teleteknik.goteborg.se> on 2000/10/05 12:24:34 UTC

Return values and integer promotion

Hi

This is about a minor detail.

I've been playing with the (experimental) DOM_NodeFilter.
The pure virtual method acceptNode() has a return type of
'short'. As I understand it, one is expected to return one
of the enumerated FilterAction values in the class (ie 
FILTER_ACCEPT, FILTER_SKIP and FILTER_REJECT). My compiler
thinks of enumerated values as 'int' and complains about
possible information loss when I return them as 'short'. I
think it is correct (ARM view) to regard enumerated values
as 'int' even if not all compilers mind. So perhaps the
return values for methods returning enumerated values should
be 'int'?

In the CORBA IDL language mapping for C++ enumerated values
are 32-bit (Yes, I know, the DOM does not specify a language
mapping).

Anyway, just a thought. I don't like to "pragma away"
compiler warnings :-).

cheers,
Tobbe
---
tobbe@cd.chalmers.se


Re: Return values and integer promotion

Posted by Dean Roddey <dr...@charmedquark.com>.
> I have a vague recollection of some kind of portability problem
> when returning enums from member functions when the definition
> of the enum is scoped to the class.  I can't remember the details,
> though.
>

It was when the enum is private. In the latest C++ spec, AFAIK, you cannot
return a class private type, even from a private method of that class. But
if the enum is public, which it would be here, it would be ok.

--------------------------
Dean Roddey
The CIDLib C++ Frameworks
Charmed Quark Software
droddey@charmedquark.com
http://www.charmedquark.com

"It takes two buttocks to make friction"
    - African Proverb




Re: Return values and integer promotion

Posted by Andy Heninger <an...@jtcsv.com>.
It does look like the definition for the constants for NodeFilter
is not quite right.

The DOM spec itself defines them as const shorts, not as an enum.
That is in the IDL, which is supposed to be a formal reference,
not an actual useful IDL mapping.

See
http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html#Traversal-
NodeFilter

Defining the constants in an enum makes sense for C++ - there's no
other reasonable way to scope constants to a class.

The DOM IDL also defines acceptNodes's return to be short, which
is where the C++ short return type came from here.

I have a vague recollection of some kind of portability problem
when returning enums from member functions when the definition
of the enum is scoped to the class.  I can't remember the details,
though.

I lean towards changing the C++ return type for acceptNode()
to int.  Anyone see any possible problems with this?

Also, the enum for FilterAction needs to explicitly list the
numerical constants from the DOM spec.  It doesn't now.

Thanks for catching this problem.

Andy Heninger
IBM XML Technology Group, Cupertino, CA
heninger@us.ibm.com


----- Original Message -----
From: "Torbjörn Bäckström" <to...@teleteknik.goteborg.se>
To: <xe...@xml.apache.org>
Sent: Thursday, October 05, 2000 3:24 AM
Subject: Return values and integer promotion


> Hi
>
> This is about a minor detail.
>
> I've been playing with the (experimental) DOM_NodeFilter.
> The pure virtual method acceptNode() has a return type of
> 'short'. As I understand it, one is expected to return one
> of the enumerated FilterAction values in the class (ie
> FILTER_ACCEPT, FILTER_SKIP and FILTER_REJECT). My compiler
> thinks of enumerated values as 'int' and complains about
> possible information loss when I return them as 'short'. I
> think it is correct (ARM view) to regard enumerated values
> as 'int' even if not all compilers mind. So perhaps the
> return values for methods returning enumerated values should
> be 'int'?
>
> In the CORBA IDL language mapping for C++ enumerated values
> are 32-bit (Yes, I know, the DOM does not specify a language
> mapping).
>
> Anyway, just a thought. I don't like to "pragma away"
> compiler warnings :-).
>
> cheers,
> Tobbe
> ---
> tobbe@cd.chalmers.se
>
>



Re: Return values and integer promotion

Posted by Juergen Hermann <jh...@web.de>.
On Thu, 5 Oct 2000 12:24:34 +0200, Torbjörn Bäckström wrote:

>as 'int' even if not all compilers mind. So perhaps the
>return values for methods returning enumerated values should
>be 'int'?

Actually, they should be of the enum type.


Ciao, Jürgen

--
Jürgen Hermann, Developer (jhe@webde-ag.de)
WEB.DE AG, http://webde-ag.de/