Recent

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

funlw65

  • Full Member
  • ***
  • Posts: 148
    • 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
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

winni

  • Hero Member
  • *****
  • Posts: 3197
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: 148
    • 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 :) .
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

af0815

  • Hero Member
  • *****
  • Posts: 1291
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