Q: Can GNAT translate non-complex Ada 95 code using only the simple Ada libraries of Ada.Text_IO, Ada.Strings, Ada.Strings.Unbounded, and Ada.Calendar into C? Now apparently closed in the negative

10/20/2024

Question to iask ai:

Can GNAT translate non-complex Ada 95 code using only the simple Ada libraries of Ada.Text_IO, Ada.Strings, Ada.Strings.Unbounded, and Ada.Calendar into C?

Final Answer [implying probability that the answer is correct at 100%]

Yes, GNAT can translate non-complex Ada 95 code using only the simple libraries of Ada.Text_IO, Ada.Strings, Ada.Strings.Unbounded, and Ada.Calendar into C.

Is this answer above correct?

If so, is the method below correct?

The steps required are: [Probability that the answer below is correct: 95% ]

Step 4: Translate to C To translate your compiled code into C, you can use the -gnatc option with GNAT. This option instructs GNAT to generate C code instead of compiling directly into an executable.

Run the following command:

gnatmake -gnatc example.adb

This will produce C source files corresponding to your original Ada code.


Added 10/21/2024 after 23 views:

The more specific follow on question to iask.ai on 10/21/2024 was:

For GNAT, is the gnatmake switch -gnatc capable of reading an adb Ada file with its corresponding ads Ada file then to output C code?

Answer: [with implied 100% probability]

Thus, it can be concluded that the -gnatc switch in GNAT is indeed capable of reading an ADB Ada file along with its corresponding ADS Ada file to output C code .

However other questions regarding this are denied by iask.ai to say the -gnatc switch invokes more thorough file fidelity checks but unrelated to Ada input and C output. For example this “In summary, the -gnatc switch serves as a diagnostic tool within the GNAT compiler to ensure that Ada source code adheres to language specifications without producing any output files.” contradicts emission of C-code products.

But " The -gnatc switch in the context of the GNAT Ada compiler does not produce C-code from Ada source files. Instead, it is used to check the semantics of Ada package specifications (.ads ) or subprogram specifications without generating code. When you use -gnatc with an Ada file, it instructs the compiler to verify that the specified unit adheres to the language’s rules and semantics, but it does not compile or generate any object code or C-code."

Hence I answered my own question, apparently, in the negative, after 32 views.

FSF GNAT cannot convert Ada code to C. However, AdaCore’s GNAT Pro does have their Common Code Generator (CCG) option which can convert a subset of Ada to C (1. Getting Started — GNAT Pro Common Code Generator User's Guide Supplement 26.0w documentation ). I have only learned about CCG a few years ago, but have never used it.

1 Like

It is really unhelpful for you to delete all your posts. It makes following the thread much more difficult than need be.

Found a turnkey solution to translate Ada 95 to C which renders this topic moot.

Do you mind telling us what it is?

added in edit: looking back at the original post, I see it’s heavily edited. I’ve followed the thread on occasion, but didn’t realize you’d edited the original post. All the same, I’m not sure if Step 4 is supposed to be the turnkey solution, or if you found something else, because Step 4 is followed by some cautionary/contradictory verbiage (I’m having trouble understanding precisely what it’s saying) and concludes with, “Hence I answered my own question, apparently, in the negative” (emphasis added), which I seem to remember was already there in the original, unedited post.

Hence my request for clarification.

It turns out that the dunce online code converter based on AI has absolutely no legal guarantee of source code confidentiality, so my statement re an Ada to C solution was perfunctory.

A better potential solution just came up in fact, I prefer not to say whom, that is essentially mapping bytes directly into an FPGA which I did not think could be done but turns out to be viable as a neat end run.

The TB source produces a 650 KB exe, and the Ada95 source produces a 350 KB exe. The difference in size is because TB while written in machine code by Kemeny and Kurtz uses p-code, and the perfect 80386 Ada95 compiler does not.

While this new approach does not produce the goal of portable VHDL code, it is a solution towards taking orders from defense departments to specify the part they want from any compatible manufacturer.

I now assume this topic and thread is closed, namely that I discovered GNAT Pro CCG cannot convert Ada95 code with no tasking into C code as may be claimed.

For further correspondence, please use M8VL4@yahoo.com rather than this public forum which is closely monitored by moderators.