comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve Folly" <steve@follysplace.demon.co.uk>
Subject: Re: "#define" and C2Ada
Date: 2000/01/22
Date: 2000-01-22T00:00:00+00:00	[thread overview]
Message-ID: <948538393.7183.0.nnrp-13.c2de848f@news.demon.co.uk> (raw)
In-Reply-To: o%Wh4.843$E46.5675@telenews.teleline.es

[-- 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







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

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

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