How to translate this:
struct a;Mattias

Mailing lists / fpc-pascal / 2008-07
16 messages · 10 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
How to translate this:
struct a;Mattias
er...
Closest would be:
type
record = foo
bar : integer;
end;
var
a : foo;I _think_.
g.
How to translate this: struct a; Mattias
Mattias Gärtner wroteHow to translate this: struct a;
Isn't this a forward declaration? So sometime later it needs to declare 'struct a { ... };' ?
Micha
er... Closest would be: type record = foo bar : integer; end; var a : foo; I _think_. g.
No. The a is not an instantiation, it's an incomplete type. I wouldn't translate it at all, it's merely a forward declaration. As the (C-)compiler wouldn't know the size of the type at this point, it can't instantiate anything (although pointer to it would be possible, AFAIR).
Vinzent.
er... Closest would be: type record = foo bar : integer; end; var a : foo; I _think_. g.
Gene Buckle wrote> How to translate this: > > struct a;
a: pointer;I would do something like this:
C
----------------------------
struct product {
int weight;
float price;
} ;
product apple;
-----------------------------
Pascal
----------------------------
Type
product = record
weight: Integer ;
price: double;
end;
Var
apple: product ;
----------------------------This is the reason that I do believe that is missing something on the code:
struct a;Best Regards
Lourival Mendes
2008/7/30 Jilani Khaldi :
A C-struct is merely a record. A struct with methods is a class.
struct Foo
{
Foo() : tag(0) {}
int tag;
void compute() {...}};
would be
class Foo
private
FTag: Integer;
public
constructor Create;
procedure compute;
property tag: Integer read FTag write FTag;
end;the property is not really needed of course.
Isn't this a forward declaration? So sometime later it needs to declare 'struct a { ...…
If not, can't it be translated as:
a: record end;?
Marc (not a Cist)
Yes, it can.
Thanks. I will use that.
Mattias
What for? The C statement is empty, it's not a variable and not even a type. So before…
Vinzent Höfler wroteWhat for? The C statement is empty, it's not a variable and not even a type. So before translating that into an empty Pascal-record, you should rather look at what the actually used structur in the C-code is.
It is usually used for having an opaque type, referencing it with a pointer. I would put in pascal both the empty structure and a pointer type to it.
a: record end;
pa: ^a;On Tue, 12 Aug 2008 09:39:36 +0200 Thanks. I will use that. Mattias
What for? The C statement is empty, it's not a variable and not even a type. So before translating that into an empty Pascal-record, you should rather look at what the actually used structur in the C-code is.
Vinzent.
On Wed, Aug 13, 2008 at 7:38 AM, Vinzent Höfler It is usually used for having an opaque…
But then the structures won't match, opaque or not.
Mattias provided no context to his original question, so I don't know if it would impose a problem, but usually I leave those things out until I really need them. The type as is has no storage size associated to it, so it can't even be used that way in the C-code. Sure, you can have a pointer to it, but unless you cast the hell out of it, it still won't do any good.
Vinzent.
What for? The C statement is empty, it's not a variable and not even a type. So before…
Zitat von Vinzent Höfler :
Actually the C-Code does what C can do really good: obfuscating.
If I understand the code correct, the 'struct a;' itself is never used directly. It always uses 'struct a* foo'. So foo is a pointer to an empty struct a, which probably is the C equivalent of a typed pointer. To get strong type checking, I guess, it is ok to follow Felipe's advice:
type a = record end; pa=^a;Mattias
Yeah.
Well, I guess so, but it still doesn't make a lot of sense.
That "struct a" is not empty (storage size = 0), it is even non-existant (storage size = unknown). So the C-code may shuffle around the pointers, but unless this "struct a" (the "a" not even being a type here) is instantiated somewhere (internally in some library code?) such pointers are merely typed "void*".
Vinzent.
Zitat von Vinzent Höfler :
The c compiler does not need the internals, so should the pascal bindings.
Mattias