"#define" and C2Ada 
Author Message
 "#define" and C2Ada

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;

Quote:
}

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



Tue, 09 Jul 2002 03:00:00 GMT  
 "#define" and C2Ada



Quote:
> 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



Wed, 10 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. c2ada and "typedef unsigned char X;"

2. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

3. define "variable" word

4. Redesigning "define interface"

5. defining "|" as or in Poplog Prolog

6. Lets define "pointer"

7. Lets define "pointer"

8. Naming of "defined?"

9. defining "preferences" in cosmo with code

10. use defined PROTO in "Browser.createVrmlFromString"?

11. +define+unknown="'bx" chokes verilog

12. Defining "public" functions

 

 
Powered by phpBB® Forum Software