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

  • SEARCH
  • Home
  • 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 8390811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:06:12+00:00 2026-06-09T19:06:12+00:00

I am wondering if there is a way of getting smaller / more efficient

  • 0

I am wondering if there is a way of getting smaller / more efficient assembler code from Ada generics.

For example, I have written a little dummy Ada program (main.adb) to show a generic procedure & instantiated it 6 times:

with Ada.Text_Io;
procedure Main is

   generic
      X : Natural;
      with procedure Bob (S : in String);
   procedure Thing_Gen (S : in String);

   procedure Thing_Gen (S : in String) is
   begin
      for I in 0 .. X loop
         Bob (Natural'Image (I) & " " & S);
      end loop;
   end Thing_Gen;

   procedure Alice (S : in String) is
   begin
      Ada.Text_Io.Put_Line ("Alice:" & S);
   end Alice;

   procedure Aaa is new Thing_Gen (X => 1, Bob => Alice);
   procedure Baa is new Thing_Gen (X => 2, Bob => Alice);
   procedure Caa is new Thing_Gen (X => 3, Bob => Alice);
   procedure Daa is new Thing_Gen (X => 4, Bob => Alice);
   procedure Eaa is new Thing_Gen (X => 5, Bob => Alice);
   procedure Faa is new Thing_Gen (X => 6, Bob => Alice);

begin

   Aaa("A");
   Baa("B");
   Caa("C");
   Daa("D");
   Eaa("E");
   Faa("F");

end Main;

To compile, I am using gnatmake main.adb when I look at the resulting objdump -d -S main > main.dump I see that there are 6 sections for each of the generic instantiations:

000000000040275f <main__baa.2182>:
  40275f:   55                      push   %rbp
  402760:   48 89 e5                mov    %rsp,%rbp

… < snip >

0000000000402a05 <main__caa.2187>:
  402a05:   55                      push   %rbp
  402a06:   48 89 e5                mov    %rsp,%rbp

… < snip >
etc…

each with very similar code, so what I suspect is happening is that gnatmake is using Thing_Gen as a template and expanding the code for each instantiation, rather than reusing the code with some parametetrs.

So the question is, how to get gnatmake to reuse the code of the generic, rather than copy/pasting for each instantiation ?

I would have expected the instantiations to have taken a form of :

  1. Setup Baa / apply generic parameters (I know X is to have This_Value
    & procedure Bob is at This_Address)
  2. Call Thing_Gen (which then uses what was setup to produce the
    expected result)

Resulting in reuse of Thing_Gen code. But this appears not to be the case. Explanations of why I am a noob in Assembler & Compiler issues also welcome!

NOTE: same results in Sparc & Intel ! (Intel gnatmake version 4.4.3)

  • 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-09T19:06:13+00:00Added an answer on June 9, 2026 at 7:06 pm

    I don’t think you can get Gnat to do shared generics, as code generation for generics is a matter of compiler implementor’s design choice, and AdaCore chose to replicate.

    According to this thread, RR and perhaps Irvine support shared generics.

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

Sidebar

Related Questions

I was wondering if there's an abbreviation or a more elegant way of getting
Wondering if there is any way to get the lambda expressions that result from
just wondering if there is a way to reduce the amount of code needed
Just wondering if there's a known way of getting a Mono System.Windows.Forms application to
I was wondering if there is a straightforward way of getting a user's session
I was wondering if there is a (Jquery) way of getting the first img
I am wondering if there is a way of getting the path to the
I'm just getting started with meta-programming, and am wondering if there's a way to
I was wondering if there was a way to completely lock my code while
I was wondering if there is some standardized way of getting type sizes in

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.