Page 1 of 9 123 ... LastLast
Results 1 to 10 of 84

Thread: C/C++ vs Pascal

  1. #1

    C/C++ vs Pascal

    Ok, well, with all the hype I've been hearing towards and against pascal/c/c++, I just want to know...
    What are the exact advantages/disadvantages of Pascal, C, and C++? I don't need to know, oh theres lots of tutorials, thats not a problem... I mean the actual language/compiler advantages.
    --MagicRPG--

  2. #2
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    C/C++ vs Pascal

    You know I've not read so much language debate and discussion since... well a long time as I have in this past month. :scratch:

    Anyhow.. here are the main differences as I see them and have followed on in the last oh... 10 years. [size=9px](**** I'm getting old )[/size]

    First understand that the debate that you are talking about fits roughly into 4 categories of languages, though technically it can span several different dialects. Sound complex? It is.

    The most obvious is that C & C++ are 'symbolic' languages where as Pascal & Object Pascal are more 'natural language' languages. The terms might be incorrect, [size=9px](it's been some time since I had that less way back in highschool)[/size] but the idea holds true. Pascal is more like English and C is more symbolic terms that both basically perform the same types of functions.

    Another big thing is that the C branch is more dependent on pointers for some things and not so strongly typed, where as Pascal house is strongly typed and offers pointers as an option than a requirement. I'm not so sure how strongly this holds true to Object Pascal today. Perhaps the habit is kept, but the implementation in the compilers has changed. Any FPC guys to back this up?


    C has header files and core source files where as Pascal has units and programs. [size=9px](plus libraries which I believe may only be a byproduct of Object Pascal. Someone please prove me right/wrong? I'm not 100% sure here, may have been something back in the TP7 days.)[/size] This is where you get all these "header translation" projects coming from. All these funny .h files allow C programs to access library files. (.DLLs for Win32, .SO for Linux, etc) The Pascal equivilent to this is a unit file which when is based off a 'translated header' is often called a 'wrapper'. Which I guess is some Pascal programmer's way of making fun of C people. *shrug* I dunno...


    Those are the big tree off the top of my head, but a few things that I consider moot or irrelevant to the topic of the compiler and more a feature of the IDE and tools around the language it's self are; debugging, linking, machine code optimizations and lack of hardware support. At least where are the topic of language comes to play. I can create a programming language in ancient Egyptian or some alien strange language and it can be as fast or as slow as C, Pascal, Basic or AppleTalk.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  3. #3

    C/C++ vs Pascal

    Any FPC guys to back this up?
    There is a big difference between FPC and Delphi in one aspect.
    Free Pascal allows you to perform arithmetic operations with pointers.
    Code:
    var
      p: pointer;
      a, b: integer;
    ...
    p:=p + (a*b);
    In Delphi you must add a lot of unnecessary typecasts:
    Code:
    p:=pointer(cardinal(p) + (a*b));
    Which is stupid IMO, because the pointers in themselves are a way around the strong typing.

  4. #4

    C/C++ vs Pascal

    * When you misplace or exclude a ; in C++ it is highly possible or probable you receive unclear compiler errors and perhaps even a lot of them, whereas with Pascal the information is actually more useful and clear.

    * Pascal is a safe language, while C and C++ are not.

    * Pascal is fit to be used as an effective teaching tool, while C and C++ only make matters unnecessarily difficult.

    * Nowadays FPC is the bomb: multi-platform support and very fast.




    NOTE for C/C++ programmers: do not mistake * for a pointer! They are merely to signify certain... pointe-- points made

  5. #5

    C/C++ vs Pascal

    The way of translating C headers is wrong, IMO.
    People convert C header into an unit, but the unit is not just the original headers. More often than not it contains a initialization/loading code also, the code that often doesn't work or is incompatible with your project. So you can't just use that unit, you need to modify it. But then the updated version is released, and you need to do it all again. and again.

    Why not convert C headers to Pascal, then put it into a unit using {$include ...} ?

    he Pascal equivilent to this is a unit
    No, it isn't. The units have no equivalent in C/C++.
    On the other hand, the C way of headers and core source files is perfectly applicable to Pascal. I use it to compose large units from many small fies using {$include ...}. The Free Pascal RTL is built the same way.

  6. #6

    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--

  7. #7

    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.

  8. #8

    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!

  9. #9

    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.

  10. #10

    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.

Page 1 of 9 123 ... 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
  •