Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 84

Thread: C/C++ vs Pascal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    C/C++ vs Pascal

    Hmmmm, ok. So basically, everything between C/C++ and pascal are nearly identical, except with different syntax, and more/less support available. So technically, anything possible with C/C++ is possible with Pascal?

    Thats good to know... It means I don't need to go in-depth on learning C/C++.
    --MagicRPG--

  2. #2

    C/C++ vs Pascal

    So basically, everything between C/C++ and pascal are nearly identical, [...] So technically, anything possible with C/C++ is possible with Pascal?
    No.
    They are *mostly* the same, but there are things you can do with C that you cannot with Pascal, and vice versa.
    Of course, this relates to some pretty advanced stuff, you should be quite experienced in programming to get grip of it.

    C has multiple inheritance and tons of other techniques (perverted IMO) you can't easily replicate in Pascal. Also, C has generics and Pascal doesn't (yet). I cannot be of much help here because I'm not familiar with C/C++ myself.

    Pascal has metaclasses - a unique feature you won't find in C++. So, for example, my persistency system would be impossible to create with C++.
    Metaclasses are quite powerful feature, allowing to decide created object's type at runtime in a very easy and elegant manner. Metaclasses also allow you to write, for example, methods for class to clone itself that will work correctly with all its descendants:

    Code:
    type
      TFrog = class
        constructor RibbitCreate; virtual;
        function OneMore: TFrog;
      end;
      CFrog = class of TFrog;
    
      TToad = class(TFrog);
      ...
    
      function TFrog.OneMore: TFrog;
      begin
        Result:=CFrog(Self.ClassType).RibbitCreate;
          //Typecast to CFrog is required here because ClassType() returns TClass,
          //  but TClass doesn't have the RibbitCreate constructor 
      end;
    If you call TToad's OneMore you will get TToad, not TFrog, despite the fact that the method is inherited from TFrog unchanged.

    AFAIK, you can't do such things in C.

  3. #3

    C/C++ vs Pascal

    Why such advanced things? One can give much more practical examples, units for example.

    I.e. the following isn't possible in C:

    [pascal]
    procedure write(lmy_linked_list;var f:file);

    begin
    if l<>nil then
    begin
    system.write(f,l^.data);
    write(l^.next);
    end;
    end;
    [/pascal]

    Summing it up, in C you are constantly evading already existing identifiers. In Pascal, hakuna matata!

  4. #4

    C/C++ vs Pascal

    I'm no specialist or professional, but I've had a little share of C, C++ and Pascal (but not Object Pascal).

    To me it's those little things like ranges or subranges like 0..17 or something like that which -- as I remember -- cannot be done in C or C++.

    Or what about...
    [pascal]
    with Thing do begin
    value1 := 7;
    value2 := 10;
    value3 := 1;
    value4 := 2;
    value5 := 344332;
    {etcetera}
    end;
    [/pascal]
    ...that instead of...
    [pascal]
    Thing.value1 := 7;
    Thing.value2 := 10;
    Thing.value3 := 1;
    Thing.value4 := 2;
    Thing.value5 := 344332;
    {etcetera}
    [/pascal]

    If I recall correctly a similar thing -- the use of with-do -- cannot be done in C or C++. It's just a beautiful simple elegant touch that is effective as I see it.

  5. #5

    C/C++ vs Pascal

    You can actually use the with-do in functions ... :twisted:

    [pascal]with TObject.Create do begin
    func_param1 := 'abc';
    AOwner := Form1;
    end;[/pascal]

    In C/C++ (AFAIK) you cannot do:[pascal]// Read until INI-File style comments.
    repeat
    inc(i);
    until (inStr[i+1] in [#13,#10,#0,';']);[/pascal]

    In fact, I even coded a semi-complete 3 byte (YES!) variant system for a variant stack for scripting! In four hours!!

    I work in ANSI-C for CGI scripting for a web interface as a part of my work. It's ugly, instable, requires work-a-rounds, and really hard to keep up to date without breaking anything. I could rewrite our whole interface in Pascal -- ignoring the time to get adjusted to Pascal CGI -- in less than half the time it has taken them to add pages and maintain the present beast.

  6. #6

    C/C++ vs Pascal

    Heh heh, what a great topic, people. I rejoice when I notice criticism (or the likes) on C/C++, heh heh


    DarknessX, check out this link: http://www.zel.org/oberon/fromctoo.htm : it's about Oberon-2 and such and C and C++. It might prove you useful.

  7. #7

    C/C++ vs Pascal

    [pascal]procedure GetRawData(const F: Single): Integer; inline;
    var
    I: Integer absolute F;
    begin
    // returns binary representation of a float in an integer
    Result := I;
    end;[/pascal]
    absolute keyword, I am not aware of an equivalent in C....aliasing one variable over another is considered hacky, but sometimes it has its uses

    also you forgot about the best, built-in support for strings and dynamic arrays with reference counting....something C(++) can only dream of (it is possible by using smart pointers in C++ but it's ugly and not used)...next extremely fast compilers compared to C++ ones (C ones can be quite fast because it's actually a lot cleaner than the monster C++ is)...then support for method pointers (function(Args): ResultType of object) which is also missing in C(++)....sets, subrange types (already mentioned), interfaces (those can be simulated with abstract base classes combined with multiple inheritance in C++)....and I guess one may find even more things which are better in Object Pascal than in C(++)....

    sometimes I wish OP would allow some equivalent for C's bitfields in structures with automatic shifting/masking to get the correct results on set/get possibly enhanced by OP's range checks....that would be cool
    class allocation on the stack is also a nice feature, on the other and it makes C++ classes just a bit more than structs and forces you to use pointers everywhere (explicitly) while in OP class instances are implicitly pointers and save you a lot of headaches.....

    all in all I'd say OP has more features which C(++) does not than C(++) has and OP doesn't have...that combined with a much less confusing syntax and easily readable code makes it a perfect choice for development....

  8. #8

    C/C++ vs Pascal

    Quote Originally Posted by Setharian
    sometimes I wish OP would allow some equivalent for C's bitfields in structures with automatic shifting/masking to get the correct results on set/get possibly enhanced by OP's range checks....that would be cool
    ✓ Check :twisted:

    Try {$bitpacking on}, then declare a packed array or record.

  9. #9

    C/C++ vs Pascal

    Quote Originally Posted by dmantione
    Try {$bitpacking on}, then declare a packed array or record.
    which compiler supports that?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  10. #10

    C/C++ vs Pascal

    no idea what that directive does....it would seem it reduces sizes of structures to a bare minimum but since I know no syntax with which I could declare fields with size of X bits I'm not sure how I can I make use of it...it isn't documented in the online documentation...besides I'm using Delphi IDE with DCC

Page 2 of 6 FirstFirst 1234 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •