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.
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.
[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....
✓ Check :twisted:Originally Posted by Setharian
Try {$bitpacking on}, then declare a packed array or record.
which compiler supports that?Originally Posted by dmantione
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
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
Simple, with bitpacking the compiler does not allocate more than needed, so use 0..1 for 1 bit, 0..3 for 2 bits, 0..7 for 3 bits etc.
[pascal]
{$bitpacking on}
program bitpackingtest;
type two_nibbles=record
a,b:0..15;
end;
begin
writeln(sizeof(two_nibbles));
end.
[/pascal]
... will output 1. It is a new feature of FPC 2.1.4 we coded for Mac Pascal compatibility. Make Borland a feature request
refer to CodeGear now still I doubt they'll listen...I haven't seen them implement a new feature users requested for a long time...only features added were just to bridge with Delphi.NET more or less....nonetheless it's a nice feature you added to FPC
You guys actually implemented bit-aligned record fields? do they also pack together on bit level or are padded to next byte? what does sizeof return for them?
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
They are bit aligned. Don't save the last byte of memory, save the last bit of memory :rambo:
[pascal]
program bitpack;
{$bitpacking on}
var aacked array[0..15] of 0..63;
begin
writeln(sizeof(a));
end.
[/pascal]
daniel@laptop:~> ./bitpack
12
daniel@laptop:~>
You know thats actually quite handy if you're working with things like older tracker module formats and the like.
How long until you think that FPC is going to start giving the current Delphi compiler a run for it's money? Besides .NET and the fact that FPC has a huge platform support base comparable to no other than GCC.
Bookmarks