Thread: InvalidOid & C++

InvalidOid & C++

From
"Jeroen T. Vermeulen"
Date:
Compiling anything that uses InvalidOid under g++ yields a warning about
the expression using an "old-style cast."  Therefore, would it be okay to
patch postgres_ext.h as follows:


*** src/include/postgres_ext.h    2003-02-22 16:24:28.000000000 +0100
--- ../postgres_ext.h    2003-03-06 21:44:11.000000000 +0100
***************
*** 28,34 ****
--- 28,38 ----
   */
  typedef unsigned int Oid;

+ #ifdef __cplusplus
+ #define InvalidOid        (Oid(0))
+ #else
  #define InvalidOid        ((Oid) 0)
+ #endif

  #define OID_MAX  UINT_MAX
  /* you will need to include <limits.h> to use the above #define */


Jeroen


Re: InvalidOid & C++

From
Bruce Momjian
Date:
How widespread is Oid(0) in C++?  I have never seen anything like that.
It looks like a function call!

---------------------------------------------------------------------------

Jeroen T. Vermeulen wrote:
> Compiling anything that uses InvalidOid under g++ yields a warning about
> the expression using an "old-style cast."  Therefore, would it be okay to
> patch postgres_ext.h as follows:
>
>
> *** src/include/postgres_ext.h    2003-02-22 16:24:28.000000000 +0100
> --- ../postgres_ext.h    2003-03-06 21:44:11.000000000 +0100
> ***************
> *** 28,34 ****
> --- 28,38 ----
>    */
>   typedef unsigned int Oid;
>
> + #ifdef __cplusplus
> + #define InvalidOid        (Oid(0))
> + #else
>   #define InvalidOid        ((Oid) 0)
> + #endif
>
>   #define OID_MAX  UINT_MAX
>   /* you will need to include <limits.h> to use the above #define */
>
>
> Jeroen
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: InvalidOid & C++

From
"Nigel J. Andrews"
Date:
On Mon, 17 Mar 2003, Bruce Momjian wrote:

>
> How widespread is Oid(0) in C++?  I have never seen anything like that.
> It looks like a function call!

It is, sort of, probably. Looks like a constructor of an instance of type
Oid. Certainly valid C++ I think, at least I'm sure something like
int(0) should work but then this is trawling through my memory somewhat.

As I don't know anything about this old style cast warning I can't say which is
supposed to be more acceptable.

>
> ---------------------------------------------------------------------------
>
> Jeroen T. Vermeulen wrote:
> > Compiling anything that uses InvalidOid under g++ yields a warning about
> > the expression using an "old-style cast."  Therefore, would it be okay to
> > patch postgres_ext.h as follows:
> >
> >
> > *** src/include/postgres_ext.h    2003-02-22 16:24:28.000000000 +0100
> > --- ../postgres_ext.h    2003-03-06 21:44:11.000000000 +0100
> > ***************
> > *** 28,34 ****
> > --- 28,38 ----
> >    */
> >   typedef unsigned int Oid;
> >
> > + #ifdef __cplusplus
> > + #define InvalidOid        (Oid(0))
> > + #else
> >   #define InvalidOid        ((Oid) 0)
> > + #endif
> >
> >   #define OID_MAX  UINT_MAX
> >   /* you will need to include <limits.h> to use the above #define */
> >
> >
> > Jeroen
> >

--
Nigel J. Andrews



Re: InvalidOid & C++

From
Bruce Momjian
Date:
Patch applied.  Thanks.

---------------------------------------------------------------------------


Jeroen T. Vermeulen wrote:
> Compiling anything that uses InvalidOid under g++ yields a warning about
> the expression using an "old-style cast."  Therefore, would it be okay to
> patch postgres_ext.h as follows:
>
>
> *** src/include/postgres_ext.h    2003-02-22 16:24:28.000000000 +0100
> --- ../postgres_ext.h    2003-03-06 21:44:11.000000000 +0100
> ***************
> *** 28,34 ****
> --- 28,38 ----
>    */
>   typedef unsigned int Oid;
>
> + #ifdef __cplusplus
> + #define InvalidOid        (Oid(0))
> + #else
>   #define InvalidOid        ((Oid) 0)
> + #endif
>
>   #define OID_MAX  UINT_MAX
>   /* you will need to include <limits.h> to use the above #define */
>
>
> Jeroen
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: InvalidOid & C++

From
"Jeroen T. Vermeulen"
Date:
On Tue, Mar 18, 2003 at 01:54:17AM +0000, Nigel J. Andrews wrote:
>
> > How widespread is Oid(0) in C++?  I have never seen anything like that.
> > It looks like a function call!
>
> It is, sort of, probably. Looks like a constructor of an instance of type
> Oid. Certainly valid C++ I think, at least I'm sure something like
> int(0) should work but then this is trawling through my memory somewhat.

That's right, it's a perfectly normal constructor.  This is the standard
way of converting one type into another without going to such radical
measures as casting.


> As I don't know anything about this old style cast warning I can't say
> which is supposed to be more acceptable.

C++ introduces new types of casts that are more specialized and well-defined
than the C-style "sledgehammer" casts:

    const_cast<type>(value)        // (add/remove consts)
    static_cast<type>(value)
    dynamic_cast<type>(value)
    reinterpret_cast<type>(value)    // (nasty)

In this case, however, no cast is required since an Oid can simply be
constructed from the number 0.  This is standard.  Perfectly normal.
Everyday practice.  Straight out of the manual, both now and 15 years
ago.  Nothing unusual.  Acceptable in polite conversation.  Probably
legal in most countries of the world.  Non-carcinogenic.  Safe for
children of all ages.  No assembly required.  Full warranty.  No
strings attached.  Safe.


Jeroen