Not widely known problem in programming? (Developers)
> Program ObjTest;
> type
> test_obj=object
> message:pchar;
> procedure Init;
> procedure Display;
> end;
>
> Procedure test_obj.Init;
> var s:string; {variable on local stack}
> begin
> s:='Hello'#0;
> message:=@s[1]; {public reference to local stack}
> end;
>
> Procedure test_obj.Display;
> begin
> writeln(message);
> end;
>
> var to:test_object;
> begin
> to.Init;
> to.Display;
> end.
I was curious about the meaning of your example. The FreePascal description of the pchar type confirms my expectation: the #0 inserts a zero terminator into the s variable, and @s[1] makes a pointer to the message data. (I think 0 would point to the string-type object's length counter?)
---
l
Complete thread:
- Not widely known problem in programming? - Laaca, 27.03.2021, 20:06 (Developers)
- Not widely known problem in programming? - ecm, 27.03.2021, 20:30
- Not widely known problem in programming? - tkchia, 28.03.2021, 08:02
- Not widely known problem in programming? - marcov, 28.03.2021, 17:44
- Not widely known problem in programming? - bretjohn, 29.03.2021, 20:03
- Not widely known problem in programming? - Laaca, 29.03.2021, 22:24
- Not widely known problem in programming? - bretjohn, 29.03.2021, 23:02
- Not widely known problem in programming? - marcov, 30.03.2021, 12:05
- Not widely known problem in programming? - bretjohn, 29.03.2021, 23:02
- Not widely known problem in programming? - ecm, 29.03.2021, 22:26
- Not widely known problem in programming? - Laaca, 29.03.2021, 22:24
- Not widely known problem in programming? - tkchia, 28.03.2021, 08:02
- Not widely known problem in programming? - ecm, 28.03.2021, 21:52
- Not widely known problem in programming? - Laaca, 29.03.2021, 05:04
- Not widely known problem in programming? - ecm, 27.03.2021, 20:30