Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

Not widely known problem in programming? (Developers)

posted by ecm Homepage E-mail, Düsseldorf, Germany, 28.03.2021, 21:52

> 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:

Back to the forum
Board view  Mix view
22049 Postings in 2034 Threads, 396 registered users, 208 users online (0 registered, 208 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum