开发者

address representation in ada

I have pasted a code below which is in Ada language.I need some clarification on some implementations.

  C  : character;

  Char : character;
  type Myarr_Type is array (character range 'A'..'K') of character;
  Myarr : Myarr_Type := ('A','B','C','D','E','F','G','H','I','J','K');

  Next_Address := Myarr'address --'
  Last_Address := Next_Address + Storage_Offset'(40); --'

   return P2 + Storage_Offset'(4); --'

  Last_Address := Next_Address + Storage_Offset'(4); --'

Now m开发者_Go百科y doubt is 1) what does P2 + Storage_Offset'(4) actually mean.Does that mean that its returning the address of the next element in the array which is 'B'.Storage_Offset'(4) in Ada --does this mean 4 bits or 4 bytes of memory. 2) If i assume that Last_Address points to last element of the array which is 'K', how does the arithmentic Storage_Offset'(40) satisfies the actual implementation?

Please get back to me if u need any more clarifications.

Please assume that the function does not exist. As a matter of fact,i have some ada file and my job is to convert them to C files.Since i am a beginner in ada,i faced a lot of issues with that.Please pardon in case of any confusion

Thanks Maddy


Storage_Offset is a special integeral type in package System.Storage_Elements that can be added to objects of type System.Address. What exactly the units of Address and Storage_Offset are is implementation defined, but probably just about every implementation in existence uses bytes. So Next_Address + Storage_Offset'(4) means "the address four bytes past whatever Next_Address refers to."

You talked a bit about Ada porting. In 99% of cases, that is a very stupid idea (the %1 being when you need to port to a platform that has no Ada compiler). I'd say the same thing no matter what language you are porting. It's a fool's game. The best outcome you can hope for when porting code is that after a ton of effort it works as well as it did before. With coding the best case never happens.

Ada can interface to C just fine, so it would be far smarter to keep unchanged code in Ada and only "port" stuff you need to change.

If you come across any tasking code, protected types, or custom streams you will be in a world of hurt. Those things don't really have easy C analogs.

If your bosses really have a boner for C or something, I'd suggest looking into Sofcheck's AdaMagic, which provides a service to transform Ada code to ANSI C. Back in the day (two owners prior) they used to claim that it produced maintainable C code. Either way, it will probably be far cheaper than having an inexperienced (in Ada) developer try to do it all by hand.


my_func(int P1,int P2)
{
  return P2 + Storage_Offset'(4);
}

Well, this is a C function whose body is written in Ada. There is no "+" operator taking an Integer and a Storage_Offset; perhaps you're looking for

function "+"(Left : Address; Right : Storage_Offset)
 return Address;

and perhaps you meant to call my_func(something, Next_Address)?

In that case, the expression will return the address of whatever is 4 Storage_Elements, ie bytes, after Myarr('A').

Myarr_Type is an array of Character, which with any normal compiler on any common architecture is going to be a standard 8-bit byte. So Myarr_Type objects will be 11 bytes long, not 44, and Myarr('A')'Address + 4 will be the address of Myarr('E').

If you want the address of the last element of Myarr, try

Myarr (Myarr'Last)'Address
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜