comp.lang.ada
 help / color / mirror / Atom feed
From: "Fco Jos� Perera" <fjperera@sire.es>
Subject: "#define" and C2Ada
Date: 2000/01/21
Date: 2000-01-21T00:00:00+00:00	[thread overview]
Message-ID: <o%Wh4.843$E46.5675@telenews.teleline.es> (raw)

I have a problem using the c2ada translator. c2ada needs a definition of
each macro definition in the ".py" configuration file (for example as a
const int. Always a const or a var). So I can't use this macros for defining
array sizes and a warning results.
Knows anyone how to define macros and later use these in array definitions
in order to pass this code through c2ada and obtain a suitable Ada code ?

I've explained this in an example.
 In my C code I' ve got some definitions like the explained into the
following example:
------------------------

#define MAX 10

void main (void){
 int t[MAX];

 t[0]=1;
}
----------------------
I have created a ".py" configuration file defining MAX like the
following example ".py" file:
----------------------

ac = the.source("prb.c").macro("MAX")
ac.replacement = "const int MAX = 10;"

---------------------
The result was an adb as following:
--- prb.adb------------------------------------------


with C;
with C.Ops;  use C.Ops;

package body prb is


    type int_array is
        array(C.natural_int range <>)
        of aliased C.int;

    MAX: aliased C.int := 10;

    procedure main is
        t           : aliased int_array(0..C.natural_int'Last);
    begin
        t(0) := 1;
    end main;

    pragma Convention(C, main);
    pragma Export(C, MAX, "MAX");

end prb;
----------------------------
A message error appears: "Warning: Failed reducing array index to a constant
integer value."
----------------------------
If there is not a way to obtain a suitable result for macro and arrays
managing, konws anyone how to obtain a result different of the example:
    The problem is the obtained definition:
        "MAX: aliased C.int := 10;"

Why it's "aliased C.int" and not " constant int ". This involves a
problem for me because is difficult to separate constants from the
variables in the resultant code. So is not easy to make the necessary
changes in order to convert the resultant code into final Ada.

Jose Perera






             reply	other threads:[~2000-01-21  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-21  0:00 Fco Jos� Perera [this message]
2000-01-22  0:00 ` "#define" and C2Ada Steve Folly
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox