HP SunSoft Pascal 4.0 Bedienungsanleitung Seite 144

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 333
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 143
120 Pascal 4.0 Users Guide
6
Avoid constructs that rely on strings being in static variable storage. For
example, you could use mktemp(3) in Pascal as follows:
This use is incorrect, since mktemp()modifies its argument. Instead, use the C
library routine strncpy() (see string(3)) to copy the string constant to a
declared char array variable, as in:
The commands to compile and
execute StrVar.c and
StrVarMain.p
hostname% cc -c StrVar.c
hostname% pc StrVar.o StrVarMain.p
hostname% a.out
abcdefghij
abcdefghijklmnopqrtstuvwxyz
varstr
length(v) = 6
Incorrect use of string in static
variable storage
tmp := mktemp('/tmp/eph.xxxxxx')
Correct solution using the C
library routine strncpy()
program Use_mktemp ;
procedure strncpy( var dest: univ string ;
var srce: univ string ;
length: integer) ; external c ;
procedure mktemp(var dest: univ string); external c;
...
var path: string ;
begin
...
strncpy( path, '/tmp/eph.xxxxxx', sizeof(path)) ;
mktemp( path ) ;
...
end .
Seitenansicht 143
1 2 ... 139 140 141 142 143 144 145 146 147 148 149 ... 332 333

Kommentare zu diesen Handbüchern

Keine Kommentare