G2++ Tutorial - G2++(C++)

Adding Builtin C Types to the Repertoire of G2++ Types

By capitalizing on the knowledge of stream insertion and extraction of C types built into iostream(C++), new C builtin types\(emin addition to those already hard-wired into G2++\(emcan easily and quickly be added to the repertoire of types G2++ knows how to handle. We illustrate how to do this by giving two examples.

First, suppose we want to handle doubles. The following USER type definition does the trick:

           double  USER
                   .header iostream.h
                   .null   0.0

This works because (1) double has equality and assignment (they're built into the language) and (2) iostream.h defines an inserter and extractor for double. The null attribute is necessary to prevent g2++comp(CP) from defining null via a parameterless constructor double(), which would be an error because double is not a class type.

For the second example, suppose that we want to use one of the builtin integral types, say SHORT, but the application requires that zero be treated as a significant value rather than as a synonym for null; instead, we want to use the value 9999 as a synonym for null. This rules out using the G2++ type SHORT. Fortunately, the following definition is all it takes to get the job done:

           short   USER
                   .header iostream.h
                   .null   9999

Next topic: G2 Data Language Reference
Previous topic: Stream Errors

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005