comp.lang.ada
 help / color / mirror / Atom feed
* "#define" and C2Ada
@ 2000-01-21  0:00 Fco Jos� Perera
  2000-01-22  0:00 ` Steve Folly
  0 siblings, 1 reply; 2+ messages in thread
From: Fco Jos� Perera @ 2000-01-21  0:00 UTC (permalink / 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






^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: "#define" and C2Ada
  2000-01-21  0:00 "#define" and C2Ada Fco Jos� Perera
@ 2000-01-22  0:00 ` Steve Folly
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Folly @ 2000-01-22  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2824 bytes --]


Fco Jos� Perera <fjperera@sire.es> wrote in message
news:o%Wh4.843$E46.5675@telenews.teleline.es...
> 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
>
>

What compiler and platform are you using?

You declare MAX, but you don't seem to be using it anywhere. Your t array is
0..C.natural_int'Last.

It could be complaining about C.natural_int'last in your declaration of t. I
know in the Rational Apex compiler, 'Last and 'First attributes are not
static.

It would help if you told us the line where the error is.

Incidentally, don't forget to define your (corrected) array 0..MAX - 1.
Otherwise, with 0..MAX you'll end with 11 elements; not 10.

Hope that helps.

--
Regards,
Steve Folly.
http://www.follysplace.demon.co.uk
donationsto:myaccount@mybank.co.uk







^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-01-22  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-21  0:00 "#define" and C2Ada Fco Jos� Perera
2000-01-22  0:00 ` Steve Folly

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