Unchecked conversion & external variables 
Author Message
 Unchecked conversion & external variables

These are my next set of problems in an ongoing effort to rehost some
obsolete Pascal code under GPC with a minimum of changes.

1) Is there a function under GPC similar to Ada's unchecked conversion?  The
metaware pascal I'm looking at has a non-portable retype function.

2) Is there a way of sharing variables between modules?  This would be
similar to C where a variable declared in one file and declared extern in
another.

Thanks in advance, Jim.



Sat, 12 Jul 2003 11:02:27 GMT  
 Unchecked conversion & external variables

Quote:

> These are my next set of problems in an ongoing effort to rehost some
> obsolete pascal code under GPC with a minimum of changes.

> 1) Is there a function under GPC similar to Ada's unchecked conversion?  The
> metaware pascal I'm looking at has a non-portable retype function.

I don't know Ada well, but perhaps it's something like the "type
casting" GPC supports:

  TypeName (Expression_or_Reference)

Quote:
> 2) Is there a way of sharing variables between modules?  This would be
> similar to C where a variable declared in one file and declared extern in
> another.

That's what modules are for -- sharing variables and routines. Just
declare the variable in the interface of one module and import it in
the other one. No need for any extern declarations. Or am I missing
what you mean?

Frank

--

PGP and GPG keys:           http://fjf.gnu.de/plan
Pascal code, BP CRT bugfix: http://fjf.gnu.de/programs.html
Free GNU Pascal Compiler:   http://home.pages.de/~GNU-Pascal/



Sat, 12 Jul 2003 17:53:30 GMT  
 Unchecked conversion & external variables


Quote:


> > 2) Is there a way of sharing variables between modules?  This would be
> > similar to C where a variable declared in one file and declared extern
in
> > another.

> That's what modules are for -- sharing variables and routines. Just
> declare the variable in the interface of one module and import it in
> the other one. No need for any extern declarations. Or am I missing
> what you mean?

> Frank

> --

> PGP and GPG keys:           http://fjf.gnu.de/plan
> Pascal code, BP CRT bugfix: http://fjf.gnu.de/programs.html
> Free GNU Pascal Compiler:   http://home.pages.de/~GNU-Pascal/
> > 2) Is there a way of sharing variables between modules?  This would be
> > similar to C where a variable declared in one file and declared extern
in
> > another.

> That's what modules are for -- sharing variables and routines. Just
> declare the variable in the interface of one module and import it in
> the other one. No need for any extern declarations. Or am I missing
> what you mean?

> Frank

I looked at 3 module formats from the gnu manual, and the version that looks
the best for sharing variables will not link into a C main.  I wrote the
module like this:

module mod1;

interface

    export (setx, getx, y);

    var
        x : integer;

    procedure setx( x_in : integer)
    function getx : integer;

implementation;

    procedure setx( x_in : integer);
    begin
        x := x_in;
    end;

    function getx : integer;
    begin
        y := x;
    end;

end.

Don't check my syntax, since I'm doing this off the top of my head.  I've
got
2 modules of this form that interact, and they both compile.  However, I
could not but could not link them with a C language main.   The gcc compiler
complained that there were unresolved references (p_collect_flag & p_collect
I think).  The gnu manual has a simpler (though not preferred) format that
did compile and link.  The hitch here is that I cannot share variables, only
subroutines.  Has anyone out there called pascal functions wrapped in
modules as above from C?

Thanks,  Jim.



Mon, 14 Jul 2003 09:33:57 GMT  
 Unchecked conversion & external variables

Quote:

> I looked at 3 module formats from the gnu manual, and the version that looks
> the best for sharing variables will not link into a C main.  I wrote the
> module like this:

> module mod1;

> interface

>     export (setx, getx, y);

>     var
>         x : integer;

>     procedure setx( x_in : integer)
>     function getx : integer;

> implementation;

>     procedure setx( x_in : integer);
>     begin
>         x := x_in;
>     end;

>     function getx : integer;
>     begin
>         y := x;
>     end;

> end.

> Don't check my syntax, since I'm doing this off the top of my head.  I've
> got
> 2 modules of this form that interact, and they both compile.  However, I
> could not but could not link them with a C language main.   The gcc compiler
> complained that there were unresolved references (p_collect_flag & p_collect
> I think).  The gnu manual has a simpler (though not preferred) format that
> did compile and link.

p_collect_flag and p_collect are obsolete and no more present in
current GPC versions... but other symbols are. In general, linking a
GPC program requires the GPC RTS (run time system) -- as you noted,
you might get away without it in special cases, but usually not, and
it's not in the first place dependent on the module format.

So, just link the RTS, i.e. link with gcc -lgpc, possibly you'll
also need a -L option pointing to the right directory, also make
sure you use the math library -lm. Or simply do the linking with gpc
(it also accepts C files, and it links libc anyway, so this should
work "out of the box").

Frank

--

PGP and GPG keys:           http://fjf.gnu.de/plan
Pascal code, BP CRT bugfix: http://fjf.gnu.de/programs.html
Free GNU Pascal Compiler:   http://home.pages.de/~GNU-Pascal/



Mon, 21 Jul 2003 05:25:05 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Changing types, unchecked conversions

2. SQL & variable

3. Variables in CodeSegment & Interrupt handling

4. ReportSmith & Date Variable

5. Report Smith & Report variables

6. SQL-AnyWhere Variables & Delphi 2

7. a variable variable...

8. a variable variable...

9. Variables about variables

10. #&%*$&*EDbEngineError#&%*$&*

11. .&.&.& need help about an SQL query &&&

12. External program call from TURBO PASCAL ??

 

 
Powered by phpBB® Forum Software