Hi!
I have a structure called MYSQL_ROW, which I want to port to Pascal (Access to Mysql).
In the C-Header, MYSQL_ROW is defined like this: typedef char**MYSQL_ROW;
In Pascal, I have defined MYSQLROW like: type MYSQLROW = ^CString;
Is this OK?
How do I access the follwowing:
Var row : MYSQLROW;
C PASCAL row[0] row^ row[1] ?? row[2] ?? row[3] ??
In C, it is possible to give an enumeration some predefined values like: enum my_type { first, second, third=44};
How do I do that in Pascal?
type MyType = ( first; second; third);
Thanks,
Eike Lange
8-Aug-00 09:12 you wrote:
.
Hi!
I have a structure called MYSQL_ROW, which I want to port to Pascal (Access to Mysql).
Huh ? What can this mean ? To port "a structure" ... Alone ? Gah.
In the C-Header, MYSQL_ROW is defined like this: typedef char**MYSQL_ROW;
It's not enough to know how it's defined. There are this dual pointer/array thing in C. Pascal have pointers and arrays as separate things.
In Pascal, I have defined MYSQLROW like: type MYSQLROW = ^CString;
Is this OK?
May be. But again may be not.
How do I access the follwowing:
Var row : MYSQLROW;
C PASCAL row[0] row^ row[1] ?? row[2] ?? row[3] ??
Ahh. So it's array, not just pointer. In this case something like
type mysqlrowa=array[0..100] of CString; mysqlrow=^mysqlrowa;
will do. And you can use row^[0], row^[1], ... , row^[100] (there are no limit in C but in Pascal you NEED some limit - otherwise compiler will complain).
In C, it is possible to give an enumeration some predefined values like: enum my_type { first, second, third=44};
Yep. It works since there are NO operations for enumeration in C.
How do I do that in Pascal?
WRONG question. Right one: "is it possible to do so in Pascal". Answer: "No". Why ? Pascal HAVE operations for such types (pred and succ; gpc have inc and dec I believe) so ...
type MyType = ( first; second; third);
And then if your program tries to guess how first is represented on bit level it's WRONG. By definition. Pascal compiler can define first as 0x85, second as 0x57 and third 0x11 (it'll be strange compiler indeed but it's legal).
P.S. Looks like you trying to make pascal binding for C library without C or Pascal knowleadge. Why you are doing this at all ? No offence, just curious.
8-Aug-00 14:34 you wrote:
.
Hi!
Am Die, 08 Aug 2000 schrieb Khimenko Victor:
8-Aug-00 09:12 you wrote:
Ahh. So it's array, not just pointer. In this case something like type mysqlrowa=array[0..100] of CString; mysqlrow=^mysqlrowa; will do. And you can use row^[0], row^[1], ... , row^[100] (there are no limit in C but in Pascal you NEED some limit - otherwise compiler will complain).
Ok, thats not exactely what I want to do.
Yeah ? How so ?
What about row[10000]?
Make it array[0..10000] then. Surely MySQL have some upper limer for number of rows.
But if there is no direct equivalence, I try out some other ideas.
There are NO direct equivalence. Even more: there are NO "array with unknown number of elements" type in Pascal.
P.S. Looks like you trying to make pascal binding for C library without C or Pascal knowleadge. Why you are doing this at all ? No offence, just curious.
I do not have Pascal knowledge as much as you, but I AM an experienced C-Programmer. Actually, I just want to learn GNU-Pascal, and thats a good entry-point for it, I think (GNU-Pascal does not have a MySql-Unit).
Unfortunatelly it's not always easy to make C<->Pascal binding. For example you can include '\0' character in Pascal strings. And it's equially hard to explain pascal programmer without C knowleadge why it's so problematic to put such string in MySQL as to explain C programmer without Pascal knowleadge why it's so insane to have array without known upper bound :-)
Eike Lange wrote:
In C, it is possible to give an enumeration some predefined values like: enum my_type { first, second, third=44};
How do I do that in Pascal?
I suggest to use constants (which I think what C programmers mean when they use enums like that ;-):
const first = 0; second = 1; third = 44;
This way, you can choose any values you like, and they are in fact integers, like enums are in C.
Khimenko Victor wrote:
Ahh. So it's array, not just pointer. In this case something like type mysqlrowa=array[0..100] of CString; mysqlrow=^mysqlrowa; will do. And you can use row^[0], row^[1], ... , row^[100] (there are no limit in C but in Pascal you NEED some limit - otherwise compiler will complain).
Ok, thats not exactely what I want to do.
Yeah ? How so ?
What about row[10000]?
Make it array[0..10000] then. Surely MySQL have some upper limer for number of rows.
You could do `array [0 .. MaxVarSize div SizeOf (CString) - 1]'. MaxVarSize is the maximum size of a variable, so you declare the array as large as possible and avoid any further limits. That's an ugly BP style trick, and I usually suggest to avoid it, but for interfacing to C arrays it's necessary.
Frank
Hi!
Am Die, 08 Aug 2000 schrieb Khimenko Victor:
8-Aug-00 09:12 you wrote:
Ahh. So it's array, not just pointer. In this case something like type mysqlrowa=array[0..100] of CString; mysqlrow=^mysqlrowa; will do. And you can use row^[0], row^[1], ... , row^[100] (there are no limit in C but in Pascal you NEED some limit - otherwise compiler will complain).
Ok, thats not exactely what I want to do. What about row[10000]? But if there is no direct equivalence, I try out some other ideas.
P.S. Looks like you trying to make pascal binding for C library without C or Pascal knowleadge. Why you are doing this at all ? No offence, just curious.
I do not have Pascal knowledge as much as you, but I AM an experienced C-Programmer. Actually, I just want to learn GNU-Pascal, and thats a good entry-point for it, I think (GNU-Pascal does not have a MySql-Unit).
Eike Lange
Eike Lange wrote:
Am Die, 08 Aug 2000 schrieb Khimenko Victor:
Ahh. So it's array, not just pointer. In this case something like type mysqlrowa=array[0..100] of CString; mysqlrow=^mysqlrowa; will do. And you can use row^[0], row^[1], ... , row^[100] (there are no limit in C but in Pascal you NEED some limit - otherwise compiler will complain).
Ok, thats not exactely what I want to do. What about row[10000]? But if there is no direct equivalence, I try out some other ideas.
Victor is right: This is the direct equivalent.
In C, every pointer can be used as a pointer to an array of the target type, and the identifier of every array (without the []) represents the address of the array, not the array itself.
In this sense, there are either no real arrays in C, or there are no real pointers, only pointers to arrays. ;-)
Concerning enumerated types, GNU Pascal uses the same backend as GNU C does. If there is no striking reason to change this one day, I'd vote for fixing this as a feature of compatibility to GNU C.
Peter
8-Aug-00 15:10 you wrote:
. Eike Lange wrote:
Am Die, 08 Aug 2000 schrieb Khimenko Victor:
Ahh. So it's array, not just pointer. In this case something like type mysqlrowa=array[0..100] of CString; mysqlrow=^mysqlrowa; will do. And you can use row^[0], row^[1], ... , row^[100] (there are no limit in C but in Pascal you NEED some limit - otherwise compiler will complain).
Ok, thats not exactely what I want to do. What about row[10000]? But if there is no direct equivalence, I try out some other ideas.
Victor is right: This is the direct equivalent.
In C, every pointer can be used as a pointer to an array of the target type, and the identifier of every array (without the []) represents the address of the array, not the array itself.
In this sense, there are either no real arrays in C, or there are no real pointers, only pointers to arrays. ;-)
There are no real arrays in C AND there are no real pointers. This is C strenght and this is disaster as well.
Concerning enumerated types, GNU Pascal uses the same backend as GNU C does. If there is no striking reason to change this one day, I'd vote for fixing this as a feature of compatibility to GNU C.
Hmm. Surely this program must emit run-time error: -- cut -- type my_type=(a,b,c); var x:my_type; function my_proc(x:my_type):my_type; begin my_proc:=pred(x); end; begin x:=my_proc(a); end. -- cut -- I was unable to get one but I think it's temporary limitation, right ? C have no operations for enums while Pascal have so I'm not sure if GCC backend is powerfull enough for Pascal...
Khimenko Victor wrote:
Hmm. Surely this program must emit run-time error: -- cut -- type my_type=(a,b,c); var x:my_type; function my_proc(x:my_type):my_type; begin my_proc:=pred(x); end; begin x:=my_proc(a); end. -- cut -- I was unable to get one but I think it's temporary limitation, right ?
Right.
C have no operations for enums while Pascal have so I'm not sure if GCC backend is powerfull enough for Pascal...
We need to produce explicit code for such checks.
I think that build_pascal_binary_op() is the correct place to check whether the result fits in its type.
Peter