AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Warum ist PChar ^= @String[1]?

Ein Thema von d3g · begonnen am 4. Jan 2003 · letzter Beitrag vom 6. Jan 2003
 
Benutzerbild von d3g
d3g

Registriert seit: 21. Jun 2002
602 Beiträge
 
#1

Warum ist PChar ^= @String[1]?

  Alt 4. Jan 2003, 22:08
Ich bin gerade dabei meine C-Kenntnisse zu vertiefen und dabei ist mir etwas aufgefallen. Ein PChar entspricht einem char* in C(++), sein Ende wird durch #0 angezeigt. Ein String ist ebenfalls ein Pointer auf ein Char, jedoch sind 8 Byte Daten, unter anderem die Länge des Strings:
Zitat von Kylix 3 Hilfe zu 'Long Strings':
AnsiString, also called a long string, represents a dynamically allocated string whose maximum length is limited only by available memory.
A long-string variable is a pointer occupying four bytes of memory. When the variable is empty--that is, when it contains a zero-length string--the pointer is nil and the string uses no additional storage. When the variable is nonempty, it points a dynamically allocated block of memory that contains the string value. The eight bytes before the location contain a 32-bit length indicator and a 32-bit reference count. This memory is allocated on the heap, but its management is entirely automatic and requires no user code.
Der Pascalstring ist nicht nullterminiert (sonst könnte man ja Pascalstrings auch einfach API-Funktionen übergeben).

Daraus ergibt sich mein Problem @String[1] ist ein char* aber woher soll eine API-Funktion wissen, wie lang der String ist, wenn nicht zufällig im Speicherbereich danach binäre Nullen stehen?

Danke im Voraus,
d3g
-- Crucifixion?
-- Yes.
-- Good. Out of the door, line on the left, one cross each.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:05 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz