Re: [fpc-pascal] Empty record inside another record ?
There is another major drawback to your supposedly better method: Object inheritance forces all fields to be accessable from the root: SomeRoot.SomeField := ...; While nesting has nice grouping: SomeRoot.SomeHeader.SomeOtherHeader.SomeField := 5; Bye, Skybuck. - Original Message - From: Daniël Mantione [EMAIL PROTECTED] To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org Sent: Saturday, February 16, 2008 5:24 PM Subject: Re: [fpc-pascal] Empty record inside another record ? Op Fri, 15 Feb 2008, schreef Skybuck Flying: To me it seems like some kind of trick, to extend a record at runtime. The empty record field, functions as a sort of offset/label/pointer if you will to the new fields that will will be extended to the record by simply allocating more memory then the size of the record. Then this label/field can be used as a sort of offset, by typecasting it to some extension record type. Could be pretty handy, quite impressive trick. However, is it safe to use ? Empty records are valid Pascal. I cannot find anything in the documentation about this ? Nothing in the documentation says it is forbidden either. The reason it is not explicetely mentioned is because there exists a much better method, objects: type base_structure=object field1:byte; end; extended_structure=object(base_structure) field2:byte; end; Daniël ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Op Fri, 29 Feb 2008, schreef Skybuck Flying: There is another major drawback to your supposedly better method: Object inheritance forces all fields to be accessable from the root: SomeRoot.SomeField := ...; While nesting has nice grouping: SomeRoot.SomeHeader.SomeOtherHeader.SomeField := 5; I'd say it is a metter of taste. Anyway, you are free to use any method you like as both are valid code. End of discussion. Daniël___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Finally there is another question remaining: Are objects always packed ? If not then it could be a problem. Something which records do allow. Bye, Skybuck. - Original Message - From: Daniël Mantione [EMAIL PROTECTED] To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org Sent: Saturday, February 16, 2008 5:24 PM Subject: Re: [fpc-pascal] Empty record inside another record ? Op Fri, 15 Feb 2008, schreef Skybuck Flying: To me it seems like some kind of trick, to extend a record at runtime. The empty record field, functions as a sort of offset/label/pointer if you will to the new fields that will will be extended to the record by simply allocating more memory then the size of the record. Then this label/field can be used as a sort of offset, by typecasting it to some extension record type. Could be pretty handy, quite impressive trick. However, is it safe to use ? Empty records are valid Pascal. I cannot find anything in the documentation about this ? Nothing in the documentation says it is forbidden either. The reason it is not explicetely mentioned is because there exists a much better method, objects: type base_structure=object field1:byte; end; extended_structure=object(base_structure) field2:byte; end; Daniël ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Op Sun, 24 Feb 2008, schreef Skybuck Flying: Finally there is another question remaining: Are objects always packed ? No, to get packed objects you have to declare them packed. A record and object with the same field list have the same binary layout. Daniël___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
In every language I know, words can have multiple meanings. The context in which the words are used determines their meaning. One possible reason could be because there is so much to describe that coming up with unique words might be impossible or inpractical. Bye, Skybuck. Skybuck Flying schrieb: For records, I would use an extension field like: IP.Payload and UDP.Payload I would hardly call that obfuscation :) Having the same name for different things is always obfuscation. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
In every language I know, words can have multiple meanings. Natural languages yes. But they need a billion neurons that is trained for 20 years to interpret, not a simple automaton. IOW, lots of computer languages don't. One possible reason could be because there is so much to describe that coming up with unique words might be impossible or inpractical. I think the main reason is that brains naturally don't process information _without_ context. It's not just words, but also intonation, facial expression of the speaker, posture etc. Abstracting is a learned skill. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
The context in which the words are used determines their meaning. And that's exactly the problem: good code is understandable with as little as possible context. Any context depending behaviour/meaning makes code less readable and less maintainable. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Tiziano De Togni schreef: Florian Klaempfl ha scritto: Skybuck Flying schrieb: One drawback of objects already discovered: Objects cannot have the same field identifiers. Indeed, especially if you want to win an obfuscation contest. ok, this is true for object type, but it should not be extended to class types. Look at this example taken from Delphi Help: type TAncestor = class Value: Integer; end; TDescendant = class(TAncestor) Value: string; // hides the inherited Value field end; var MyObject: TAncestor; begin MyObject := TDescendant.Create; // MyObject.Value := 'Hello!'; // error TDescendant(MyObject).Value := 'Hello!'; // works! end; it compiles correctly in Delphi (5 and 7) but FPC (v2.2.0 - compiled with Params Values= -S2cdgi -OG1 -gl -WG -vewnhi) still says that there is a duplicate identifier Value... am I correct? This is not allowed in {$mode objfpc}, because of the reasons Florian memtioned. It is allowed in {$mode delphi}. Vincent ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
On 19 Feb 2008, at 10:16, Tiziano De Togni wrote: Vincent Snijders ha scritto: Tiziano De Togni schreef: Florian Klaempfl ha scritto: Skybuck Flying schrieb: One drawback of objects already discovered: am I correct? This is not allowed in {$mode objfpc}, because of the reasons Florian memtioned. It is allowed in {$mode delphi}. Vincent errr... I tryied various combinations of options before posting, but did not try {$mode Delphi}... :-( -S2 is the same as {$mode objfpc} and -Sd is the same as {$mode delphi}. With -S2cdgi you are trying to set both {$mode objfpc} (-S2) and {$mode delphi} (-Sd). There is a bug in the compiler though, because for some reason -S2d does not seem to properly set Delphi mode (or unset objfpc mode) while it should. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
For records, I would use an extension field like: IP.Payload and UDP.Payload I would hardly call that obfuscation :) Bye, Skybuck. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Skybuck Flying schrieb: For records, I would use an extension field like: IP.Payload and UDP.Payload I would hardly call that obfuscation :) Having the same name for different things is always obfuscation. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Vincent Snijders ha scritto: Tiziano De Togni schreef: Florian Klaempfl ha scritto: Skybuck Flying schrieb: One drawback of objects already discovered: am I correct? This is not allowed in {$mode objfpc}, because of the reasons Florian memtioned. It is allowed in {$mode delphi}. Vincent errr... I tryied various combinations of options before posting, but did not try {$mode Delphi}... :-( going back to read the manuals... to Bee: Not so sure now, compilation depends on a lot of details... -- tiziano __ http://digilander.libero.it/tizzziano/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
var MyObject: TAncestor; This is the problem. it compiles correctly in Delphi (5 and 7) Are you sure? It fails on my Delphi 7. -Bee- has Bee.ography at: http://beeography.wordpress.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
For records, I would use an extension field like: IP.Payload and UDP.Payload I would hardly call that obfuscation :) But the whole idea of inheritance is that child fields and methods are also available in UDP. Have a look at a basis OOP tutorial. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Skybuck Flying schrieb: One drawback of objects already discovered: Objects cannot have the same field identifiers. Indeed, especially if you want to win an obfuscation contest. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Florian Klaempfl ha scritto: Skybuck Flying schrieb: One drawback of objects already discovered: Objects cannot have the same field identifiers. Indeed, especially if you want to win an obfuscation contest. ok, this is true for object type, but it should not be extended to class types. Look at this example taken from Delphi Help: type TAncestor = class Value: Integer; end; TDescendant = class(TAncestor) Value: string; // hides the inherited Value field end; var MyObject: TAncestor; begin MyObject := TDescendant.Create; // MyObject.Value := 'Hello!'; // error TDescendant(MyObject).Value := 'Hello!'; // works! end; it compiles correctly in Delphi (5 and 7) but FPC (v2.2.0 - compiled with Params Values= -S2cdgi -OG1 -gl -WG -vewnhi) still says that there is a duplicate identifier Value... am I correct? -- tiziano __ http://digilander.libero.it/tizzziano/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Well ok, I see one benefit of using objects so far. No extension field needed per record/object, makes the code less complex ;) Bye, Skybuck. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Empty record inside another record ?
To me it seems like some kind of trick, to extend a record at runtime. The empty record field, functions as a sort of offset/label/pointer if you will to the new fields that will will be extended to the record by simply allocating more memory then the size of the record. Then this label/field can be used as a sort of offset, by typecasting it to some extension record type. Could be pretty handy, quite impressive trick. However, is it safe to use ? I cannot find anything in the documentation about this ? Seems to be an old trick as well. Gonna copy this stuff and ask on free pascal compiler list, maybe they know something about this ;) I wonder if free pascal supports this trick as well ;) Bye, Skybuck. Skybuck Flying [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello, What's going on here: type TsomeRecord = record SomeField : integer; SomeEmptyRecord : record end; end; How can SomeEmptyRecord be usefully used ? What is it ? SizeOf(TsomeRecord) returns 4, kinda weird ?! Bye, Skybuck. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Empty record inside another record ?
Op Fri, 15 Feb 2008, schreef Skybuck Flying: To me it seems like some kind of trick, to extend a record at runtime. The empty record field, functions as a sort of offset/label/pointer if you will to the new fields that will will be extended to the record by simply allocating more memory then the size of the record. Then this label/field can be used as a sort of offset, by typecasting it to some extension record type. Could be pretty handy, quite impressive trick. However, is it safe to use ? Empty records are valid Pascal. I cannot find anything in the documentation about this ? Nothing in the documentation says it is forbidden either. The reason it is not explicetely mentioned is because there exists a much better method, objects: type base_structure=object field1:byte; end; extended_structure=object(base_structure) field2:byte; end; Daniël___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal