• OT - ChatGPT is better than I thought.

    From Alan Browne@21:1/5 to All on Sun Oct 15 15:51:57 2023
    XPost: comp.sys.mac.system

    Preamble: I suck at C and I'm proficient in Pascal.

    While debugging a piece of C I got into a serious case of pointer mangling.

    So, I asked ChatGPT to prepare a table comparing the two.

    "please prepare a table comparing pointer data types and pointer
    operands between FreePascal and C. Use FreePascal as the starting
    point."

    Resulted in a nicely prepared table and I quickly debugged my program
    (for slow values of quickly).

    But that's not it...

    Then, on a whim: I asked: "
    prepare a comparison of pascal record to C struc where the pascal record
    has elements: a, b: word; c:array [1..10] of real; and next which is a pointer to the record type.

    And it did. And it made an error. So I said to it:
    "I believe you need to first have a pointer to the MyRecord such as: MyRecordPtr = ^MyRecord before the record and next should be of type MyRecordPtr."

    ChatGPT replied:
    "You are absolutely correct, and I apologize for the oversight. In both
    Pascal and C, when you have a pointer to a record or struct within the
    same type definition, you should declare a type for that pointer first.
    Here's the corrected comparison:"

    and put out the correct form (which is - for the case requested):

    type
    MyRecordPtr = ^MyRecord; // Declare a pointer type
    MyRecord = record
    a, b: Word;
    c: array[1..10] of Real;
    next: MyRecordPtr; // Use the pointer type
    end;

    and for C:

    struct MyStruct {
    unsigned short a;
    unsigned short b;
    float c[10];
    struct MyStruct* next;
    };

    (Nasty C letting programmers declare new types and vars on the fly ...
    sigh).


    --
    “Markets can remain irrational longer than your can remain solvent.”
    - John Maynard Keynes.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From moi@21:1/5 to Alan Browne on Mon Oct 16 01:56:29 2023
    XPost: comp.sys.mac.system

    On 15/10/2023 20:51, Alan Browne wrote:

    Preamble: I suck at C and I'm proficient in Pascal.

    While debugging a piece of C I got into a serious case of pointer mangling.

    So, I asked ChatGPT to prepare a table comparing the two.

       "please prepare a table comparing pointer data types and pointer
        operands between FreePascal and C.  Use FreePascal as the starting
        point."

    Resulted in a nicely prepared table and I quickly debugged my program
    (for slow values of quickly).

    But that's not it...

    Then, on a whim: I asked: "
    prepare a comparison of pascal record to C struc where the pascal record
    has elements:   a, b: word; c:array [1..10] of real; and next which is a pointer to the record type.

    And it did.  And it made an error.  So I said to it:
    "I believe you need to first have a pointer to the MyRecord such as: MyRecordPtr = ^MyRecord before the record and next should be of type MyRecordPtr."

    ChatGPT replied:
    "You are absolutely correct, and I apologize for the oversight. In both Pascal and C, when you have a pointer to a record or struct within the
    same type definition, you should declare a type for that pointer first. Here's the corrected comparison:"

    and put out the correct form (which is - for the case requested):

    type
      MyRecordPtr = ^MyRecord;  // Declare a pointer type
      MyRecord = record
        a, b: Word;
        c: array[1..10] of Real;
        next: MyRecordPtr;  // Use the pointer type
      end;

    and for C:

    struct MyStruct {
      unsigned short a;
      unsigned short b;
      float c[10];
      struct MyStruct* next;
    };

    (Nasty C letting programmers declare new types and vars on the fly ...
    sigh).


    Hmmm.
    Those declarations do not represent the same types.
    [1..10] is not the same as [10].
    --
    Bill F.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alan Browne@21:1/5 to moi on Mon Oct 16 09:02:51 2023
    XPost: comp.sys.mac.system

    On 2023-10-15 20:56, moi wrote:
    On 15/10/2023 20:51, Alan Browne wrote:

    and put out the correct form (which is - for the case requested):

    type
       MyRecordPtr = ^MyRecord;  // Declare a pointer type
       MyRecord = record
         a, b: Word;
         c: array[1..10] of Real;
         next: MyRecordPtr;  // Use the pointer type
       end;

    and for C:

    struct MyStruct {
       unsigned short a;
       unsigned short b;
       float c[10];
       struct MyStruct* next;
    };

    (Nasty C letting programmers declare new types and vars on the fly ...
    sigh).


    Hmmm.
    Those declarations do not represent the same types.

    For Pascal "Real" is platform dependent and can be 32 or 64 bits.

    [1..10] is not the same as [10].

    In C it would be 0 based, but in both you get a 10 element array of real numbers.

    --
    “Markets can remain irrational longer than your can remain solvent.”
    - John Maynard Keynes.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)