Thread: C++ and pascal

Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. C++arl!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    Stockholm
    Posts
    165
    Rep Power
    18

    C++ and pascal


    I made this fibonacci-series program in C++ and in pascal and noted that the pascal version is 150k and the C++ is 464k. How can there be such a difference in size?

    The pascal code:
    Code:
    program fibbonacci;
    uses
      crt;
    var
      x, y, temp : longint;
      p, i : byte;
    begin
      clrscr;
      writeln('This program handles the fibonacci series');
      write('Enter length of series:');
      readln(p);
      i := 1;
      x := 1;
      y := 0;
      while i <= p do begin
        inc(i);
        temp := x;
        x := y;
        y := temp+y;
        write(y, ' ');
      end;
      writeln();
      writeln('Press ENTER.');
      readln();
    end.
    And this is the C++ code:
    Code:
    #include<iostream>
    
    using namespace std;
    
    int main(){
             int x;
             int y;
             int temp;
             int i;
             
             cout<<"This program handels the fibonacci series \n";
             cout<<"Enter length of series:";
             cin>>i;
             cin.ignore();
             x = 1;
             y = 0;
             for (int p = 1; p<=i; p++){
                 temp = x;
                 x = y;
                 y = x+temp;
                 cout<<y<<" ";
                 }
             cout<<endl<<"Press ENTER.";   
             cin.get();
             }
    Could this be because some big unit that C++ uses? Oh yeah, I use FPC and Bloodshed Dev-C++ compilers.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    With FreePascal, I always have issues when compiling, everything seems to compile to a very large size, it wasn't like that for me in past versions. As for the C++, sounds like you may be compiling in Debug Mode. Make sure it is set to Release Mode when you compile.

    FPC lets you use a certain directive within source codes so that when another source imports that source, the first source only exports what the second source uses. This should cut back on the size of the produced executable. I'm guessing that the sources that are used in your program by default, such as System do not have this directive in their source. And you cannot figure out if they have it or not because it is not Pascal code that you can view of System (as well as other libraries that come with FPC), it is something output by FPC that converts the Pascal to maybe byte-code? But they are usually in .ppu files and you cannot see Pascal code from them.
    Last edited by Yegg`; July 17th, 2006 at 12:22 PM.
  4. #3
  5. C++arl!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    Stockholm
    Posts
    165
    Rep Power
    18
    Originally Posted by Yegg`
    With FreePascal, I always have issues when compiling, everything seems to compile to a very large size, it wasn't like that for me in past versions. As for the C++, sounds like you may be compiling in Debug Mode. Make sure it is set to Release Mode when you compile.
    Nothing to do about the size of the pascal exe then =(, but how do you change the C++ debug mode (noob warning) to normal mode cuz I didnt find any 'release mode' (or something like that) option in the compiler options menu and I cant recall activley uisng the debuger. BTW, wich C++ compiler do you think is the best?
  6. #4
  7. Periodically energetic Perler
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2005
    Location
    Dublin, Ireland
    Posts
    2,265
    Rep Power
    537
    what compiler are you using?

    In dev c++, in the project options, there is a "compiler options" tab, clicking on this and then linker you will see an option "generate debugging information". Most compilers will have something similar.

    which compiler is the best depends on how much you are going to spend.

    2 good free ones for windows (and probably linux to but I dont know):
    Dev c++
    lcc

    Microsoft have released Visual C++ Express edition for free. I've never used it myself.

    Hope this helps.
    Displeaser
    Vi Veri Veniversum Vivus Vici.
  8. #5
  9. C++arl!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    Stockholm
    Posts
    165
    Rep Power
    18
    Thnx man. I used the Dev-C++ 5 wich is at the moment a beta version so I switched to version 4 and when I compile the same source as above it compiles to a nice and handy 72k exe. =)
  10. #6
  11. Periodically energetic Perler
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2005
    Location
    Dublin, Ireland
    Posts
    2,265
    Rep Power
    537
    Originally Posted by lingon
    Thnx man. I used the Dev-C++ 5 wich is at the moment a beta version so I switched to version 4 and when I compile the same source as above it compiles to a nice and handy 72k exe. =)
    Cool
    Vi Veri Veniversum Vivus Vici.
  12. #7
  13. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    For Visual C++ on Windows, I prefer Microsoft Visual C++ 6. I can't recommend software piracy on these forums. Do what you need to get a copy, if you're that into C++ for Windows then I do recommend it, it's my favorite.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2006
    Posts
    2,270
    Rep Power
    1736
    Originally Posted by Yegg`
    For Visual C++ on Windows, I prefer Microsoft Visual C++ 6. I can't recommend software piracy on these forums. Do what you need to get a copy, if you're that into C++ for Windows then I do recommend it, it's my favorite.
    If you have access to Visual Studio .NET 2005, definitely use that for Windows development. It's compiler is amazingly good and optimizes very well.

    A suitable alternate, and for free, is using MinGW (a Win32 port of gcc) and the code blocks IDE.

    There is one more thing to note. The code can be compiled down into a very small size, mingw or VS. First, you are using the iostream library. Nothing wrong with this, but if you are interested in small file size, using the C output functions is worthwhile.

    Not good enough? You can disable the default libraries assumed by the compiler. Include windows.h, and use a messagebox for output. Be sure to use WinMainCRTStartup (not main() ).
  16. #9
  17. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Talking about pascal, You know I never tried or seen any pascal codes, Can someone post up an example so I can see how it looks.
  18. #10
  19. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Originally Posted by xlordt
    Talking about pascal, You know I never tried or seen any pascal codes, Can someone post up an example so I can see how it looks.
    Code:
    function IsRegistered (Account : string) : boolean;
    
    var
    
       dbFile : text;
    
       data   : string;
    
    
    
    begin
    
       IsRegistered := FALSE;
    
       assign (dbFile, 'database.db');
    
       reset (dbFile);
    
       while not eof (dbFile) do begin
    
          readln (dbFile, data);
    
          if data = concat ('  Account:', Account) then begin
    
             IsRegistered := TRUE;
    
             close (dbFile);
    
             exit;
    
          end;
    
       end;
    
       close (dbFile);
    
    end;
    I wrote this when working on a server in Pascal using FreePascal.

    Originally Posted by Oler1s
    If you have access to Visual Studio .NET 2005, definitely use that for Windows development. It's compiler is amazingly good and optimizes very well.

    A suitable alternate, and for free, is using MinGW (a Win32 port of gcc) and the code blocks IDE.

    There is one more thing to note. The code can be compiled down into a very small size, mingw or VS. First, you are using the iostream library. Nothing wrong with this, but if you are interested in small file size, using the C output functions is worthwhile.

    Not good enough? You can disable the default libraries assumed by the compiler. Include windows.h, and use a messagebox for output. Be sure to use WinMainCRTStartup (not main() ).
    IIRC, .NET wants Windows 2000 and up? .NET also won't work properly with WINE. Microsoft Visual C++ 6 will compile programs for Windows 95 as well as Vista, doesn't rely on .NET, is very simple and efficient, uses the Windows API which works better with WINE.

    Compatibility with WINE is not important, but I think it's cool to have.

    I've never had a problem with MSVC++ 6. I like how it uses much less resources than MSVC++ 2005 Express.

    Comments on this post

    • xlordt agrees : So thats pascal :) nice.
    Last edited by Yegg`; July 19th, 2006 at 07:07 PM.
  20. #11
  21. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Thanx for the update Yegg
  22. #12
  23. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Originally Posted by xlordt
    Thanx for the update Yegg
    If you're one to use Visual Basic, or are considering Visual Basic, I recommend Pascal (definately FPC (FreePascal Compiler)) over VB ANY day! FreePascal works on many operating systems, the Gameboy Advance port has much success. VB limits you to one OS and IMO, has less power than Pascal. FPC also has Lazarus. Lazarus is a very nice, drag-and-drop RAD IDE for Pascal, IIRC using specifically FPC. Here is a screenshot of Lazarus, I've never used it but it looks great, and IIRC it runs on multiple platforms, which includes Windows.

    http://www.osnews.com/img/10607/Lazarus.gif
  24. #13
  25. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by Yegg`
    If you're one to use Visual Basic, or are considering Visual Basic, I recommend Pascal (definately FPC (FreePascal Compiler)) over VB ANY day! FreePascal works on many operating systems, the Gameboy Advance port has much success. VB limits you to one OS and IMO, has less power than Pascal. FPC also has Lazarus. Lazarus is a very nice, drag-and-drop RAD IDE for Pascal, IIRC using specifically FPC. Here is a screenshot of Lazarus, I've never used it but it looks great, and IIRC it runs on multiple platforms, which includes Windows.

    http://www.osnews.com/img/10607/Lazarus.gif
    nah no vb for me :P maybe in the future
  26. #14
  27. C++arl!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    Stockholm
    Posts
    165
    Rep Power
    18
    Originally Posted by Yegg´
    For Visual C++ on Windows, I prefer Microsoft Visual C++ 6. I can't recommend software piracy on these forums. Do what you need to get a copy, if you're that into C++ for Windows then I do recommend it, it's my favorite.
    I suppose Visual C++ is what Delphi is to pascal? Thats cool but I like those DOS programs .

    Originally Posted by Oler1s
    There is one more thing to note. The code can be compiled down into a very small size, mingw or VS. First, you are using the iostream library. Nothing wrong with this, but if you are interested in small file size, using the C output functions is worthwhile.
    Can you explain that a bit more? Remember, I'm proboably the biggest noob on the forums =). Oh and xlordt, there is some more pascal code at the top of this thread
    ~lingon
  28. #15
  29. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Originally Posted by lingon
    I suppose Visual C++ is what Delphi is to pascal? Thats cool but I like those DOS programs .
    Well, you can also write console applications using Visual C++ (whether it be Microsoft, Dev-C++, Borland, others).

    I'm not so sure if it's even wise to use the word "pascal" alone anymore. There are various "implementations" out there and only a few seem to be used more so than the rest, such as GNU Pascal, Irie Pascal, Turbo Pascal, and especially FreePascal. FreePascal supports standards from Pascal, Turbo Pascal, Delphi, and it does much more that other Pascal's do not. They are all quite unique. Like I said before, FreePascal has Lazarus IDE. This IDE is drag-and-drop just as Visual Basic is drag-and-drop, or just as Borland Delphi is (I'm pretty sure it's drag-and-drop, never used Delphi, I plan to soon). So, Pascal, IMO more specifically FreePascal, can do everything Delphi can.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo