Summary: stat_t is not the same as struct stat
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from Jesse Phillips <> 2010-11-11 
21:34:53 PST ---
The structure created by D for stat is not the same size as the one in C, and
there appears to be no communication of data between C and D. Assigns a value
to st_mode and calls a C function which prints the value and assigns its own.
At which point D prints the value (the same one it assigned). Running 32bit


D size: 100
D Assigning 65
C Size: 88
C Found: 0
C Assign: 45
D Found 65

import core.sys.posix.sys.stat;
import std.stdio;

extern(C) void modStat(stat_t* data);

void main() {
    stat_t stbuf;
    writeln("D size: ", stbuf.sizeof);
    writeln("D Assigning ", 65);
    stbuf.st_mode = 65;


    writeln("D Found ", stbuf.st_mode);

--------------- cstat.c
#include <sys/stat.h>
#include <stdio.h>

void modStat(struct stat *stbuf) {
    struct stat rrr;
    printf("C Size: %d\n", sizeof(rrr));
    printf("C Found: %d\n", stbuf->st_mode);
    printf("C Assign: %d\n", 45);
    stbuf->st_mode = 45;

Compiled with:     gcc -g -c cstat.c && dmd -gc stat.d cstat.o

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to