Recent

Author Topic: S variabile not a Null terminated string  (Read 2798 times)

funlw65

  • Full Member
  • ***
  • Posts: 116
    • Visual Pin Configurator for Nucleo 64pin boards
S variabile not a Null terminated string
« on: December 29, 2021, 08:02:12 am »
Regarding the example from this wiki page, S variable is not a Null terminated string.

https://www.freepascal.org/docs-html/ref/refsu12.html#x35-460003.2.7
Lazarus 2.2.0rc3 fpc 3.2.2, Linux, UNIX BSD
widgetset: gtk2, msegui, qt5,  bgrabitmap controls
Immediate mode GUI: raygui 3.0

winni

  • Hero Member
  • *****
  • Posts: 3098
Re: S variabile not a Null terminated string
« Reply #1 on: December 29, 2021, 08:51:21 am »
Hi!

The variable S would be a null-terminated string if the declaration was right.

'This is a null-terminated string.'#0

is longer than 30  chars. Change the declaration to

Var S : String[40]; 

Then everything is ok.

Original code:
Code: Pascal  [Select][+][-]
  1. Program three;  
  2. Var S : String[30];  
  3.     P : PChar;  
  4. begin  
  5.   S := 'This is a null-terminated string.'#0;  
  6.   P := @S[1];  
  7.   WriteLn (P);  
  8. end.

Winni

PS.: The nonsense '  was done by the Forum software
« Last Edit: December 29, 2021, 09:21:28 am by winni »

funlw65

  • Full Member
  • ***
  • Posts: 116
    • Visual Pin Configurator for Nucleo 64pin boards
Re: S variabile not a Null terminated string
« Reply #2 on: December 29, 2021, 09:40:43 am »
Yes, that was the error - I wanted to see if someone counts the chars in the string :) .
Lazarus 2.2.0rc3 fpc 3.2.2, Linux, UNIX BSD
widgetset: gtk2, msegui, qt5,  bgrabitmap controls
Immediate mode GUI: raygui 3.0

af0815

  • Hero Member
  • *****
  • Posts: 951
Re: S variabile not a Null terminated string
« Reply #3 on: December 29, 2021, 03:22:53 pm »
So it should be a Bug Report against the documentation .

( and against the forumsoftware with #39 too )
regards
Andreas

 

TinyPortal © 2005-2018