Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9235293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:59:37+00:00 2026-06-18T06:59:37+00:00

I declare a union type like this: type Access_Kind is (Named, Indexed); type Array_Type

  • 0

I declare a union type like this:

type Access_Kind is (Named, Indexed);
type Array_Type is array (0 .. 1) of Integer;

type Record_Type (Kind : Access_Kind := Access_Kind'First) is record
   case Kind is
      when Named =>
         X, Y : Integer;
      when Indexed =>
         S : Array_Type;
   end case;
end record;
pragma Unchecked_Union (Record_Type);
pragma Convention (C_Pass_By_Copy, Record_Type);

function Create (X, Y : Integer) return Record_Type;

Now when I try to create a derived type:

type Integer2 is new Record_Type;

GNAT gives me the following warning:

warning: in instantiation at line [pragma Convention...]
warning: variant record has no direct equivalent in C
warning: use of convention for type "Integer2" is dubious

So it looks like the pragma Convention is applied to the derived type, but Unchecked_Union is not. I cannot apply it to the derived type again because Record_Type already has primitive operations defined (Integer2 is defined in another package).

Is this correct behavior or a GNAT bug? How can I correctly derive from Unchecked_Union types so that the new type inherits the Unchecked_Union pragma?

GNAT Version: GNAT GPL 2012 (20120509).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:59:38+00:00Added an answer on June 18, 2026 at 6:59 am

    One possibility would be to declare the operations of Record_Type in a nested package, say Ops, so that they aren’t primitive:

    package Union is
    
       type Access_Kind is (Named, Indexed);
       type Array_Type is array (0 .. 1) of Integer;
    
       type Record_Type (Kind : Access_Kind := Access_Kind'First) is record
          case Kind is
             when Named =>
                X, Y : Integer;
             when Indexed =>
                S : Array_Type;
          end case;
       end record;
       pragma Unchecked_Union (Record_Type);
       pragma Convention (C_Pass_By_Copy, Record_Type);
    
       --  If P was declared immediately within Union, it would be
       --  primitive, and it wouldn't be possible to declare
       --  representation aspects for Integer2.
       package Ops is
          procedure P (R : Record_Type) is null;
          --  "is null" only so that I can use -gnatR without needing a
          --  body.
       end Ops;
    
       type Integer2 is new Record_Type;
       pragma Unchecked_Union (Integer2);
       pragma Convention (C_Pass_By_Copy, Integer2);
    
    end Union;
    

    Using -gnatR to display the chosen representation, I get

    $ gnatmake -c -u -f -gnatwa union.ads -gnatR
    gcc -c -gnatwa -gnatR -gnat05 union.ads
    
    Representation information for unit Union (spec)
    ------------------------------------------------
    
    for Array_Type'Size use 64;
    for Array_Type'Alignment use 4;
    for Array_Type'Component_Size use 32;
    
    for Record_Type'Size use 64;
    for Record_Type'Alignment use 4;
    for Record_Type use record
       Kind at ?? range  0 ..  -1;
       X    at  0 range  0 .. 31;
       Y    at  4 range  0 .. 31;
       S    at  0 range  0 .. 63;
    end record;
    
    for Integer2'Size use 64;
    for Integer2'Alignment use 4;
    for Integer2 use record
       Kind at ?? range  0 ..  -1;
       X    at  0 range  0 .. 31;
       Y    at  4 range  0 .. 31;
       S    at  0 range  0 .. 63;
    end record;
    

    That said, I think GNAT’s behaviour is wrong.

    ARM 13.1(0.1) says that there are representational and operational aspects, and (1) defines the representational aspects. (10) is why we need to avoid primitive operations. (15) says that representational aspects are inherited by derived types; but (15.1) says that operational aspects are not, “unless specified” for the specific aspect. I guess that “specified” means “in the ARM for language-defined aspects, or by the vendor for vendor-defined aspects”.

    B3.3(3.1) states that Unchecked_Union is a representation aspect. It should therefore be inherited.

    B3.1(0.1) states that interfacing aspects, including Convention, are representation aspects. C_Pass_By_Copy should therefore be inherited.

    I’ll work up a bug report.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I declare array like that private double[] array = new double[length] . Is it
I have a table that looks like this: DECLARE @myTable TABLE (SampleID varchar(max), site
I have oracle block like DECLARE TYPE emp_array IS VARRAY(100) OF VARCHAR2(30); VAR_PRESENTADDRESS1 varchar2(100);
I have a union that looks like this: union { int intValue; double doubleValue;
-- Given a CSV string like this: declare @roles varchar(800) select @roles = 'Pub,RegUser,ServiceAdmin'
I would like to declare a record in Delphi that contains the same layout
DECLARE @table table(XYZ VARCHAR(8) , id int) INSERT INTO @table SELECT '4000', 1 UNION
declare @d varchar set @d = 'No filter' if (@d like 'No filter') BEGIN
DECLARE @Symb varchar SET @Symb = 'Lara' SELECT Names FROM Cricket where Names like
in this SQL code DECLARE @n tinyint WHILE (@n > 0) BEGIN SELECT @n

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.