July 17th, 2006, 11:24 AM
-
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.
July 17th, 2006, 12:19 PM
-
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.
July 19th, 2006, 03:51 AM
-
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?
July 19th, 2006, 04:32 AM
-
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.
July 19th, 2006, 12:14 PM
-
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. =)
July 19th, 2006, 01:53 PM
-
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.
July 19th, 2006, 03:34 PM
-
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.
July 19th, 2006, 03:50 PM
-
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() ).
July 19th, 2006, 03:53 PM
-
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.
July 19th, 2006, 07:04 PM
-
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
Last edited by Yegg`; July 19th, 2006 at 07:07 PM.
July 19th, 2006, 08:37 PM
-
Thanx for the update Yegg
July 19th, 2006, 09:50 PM
-
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
July 19th, 2006, 10:30 PM
-
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
July 20th, 2006, 11:41 AM
-
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
July 20th, 2006, 12:28 PM
-
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.