boost crowd.
Alexey Veselovsky
alexey.veselovsky at gmail.com
Sun Nov 27 23:40:06 PST 2011
WB> How is it not true?
J> dmd -H [file] -c generates the header file for you quite nicely.
ok. Let's a see:
C++ code.
Specification:
// test.hpp file
#ifndef _test_hpp_
#define _test_hpp_
void foo();
struct Boo
{
public:
void boo();
private:
struct S {};
};
#endif
Implementation:
// file test.cpp
#include "test.hpp"
struct HelperStruct {}; // private struct for this module only
static void foo_helper() {HelperStruct s;}
void foo() { foo_helper(); }
void Boo::boo() { S ss; foo_helper(); } // method implementation in
implementation side, not in specification!
Module usage:
// file main.cpp
#include "test.hpp"
int main() {
foo(); // ok
Boo b; // ok
b.boo(); // ok
Boo::S ss; // error: struct Boo::S is private
HelperStruct s; // error: HelperStruct was not declared in this scope
return 0;
}
Now, let's try this on D:
// Implementation
module test;
public {
void foo() {foo_helper();}
struct Boo
{
public:
void boo() {S ss; foo_helper();}
private:
struct S {};
}
}
private {
struct HelperStruct {};
void foo_helper() {HelperStruct s;}
}
// Specification (generated by dmd -H test.d -c) -- test.di file
// D import file generated from 'test.d'
module test;
public
{
void foo() {foo_helper();}
struct Boo
{
public
{
void boo() {S ss; foo_helper();}
private struct S{}
}
}
}
private
{
struct HelperStruct{}
void foo_helper(){HelperStruct s;}
}
Usage:
import test;
void main() {
foo(); // ok
Boo b; // ok
b.boo(); // ok
Boo.S ss; // ok (wtf?)
HelperStruct s; // ok (wtf?!)
}
First of all I can't see difference between D's implementation and
generated specification. It looks like copy&paste. At second private
section not protect types from usage from other modules. Also I can't
write method implementation in different (implementation) file
(without inheritance).
Also there are no compiler check for test.di & test.d conformance.
In D I expect real module system like in Modula or Ada. Or at least as
in C++ (or way to emulate it). But...
PS. DMD32 D Compiler v2.056
More information about the Digitalmars-d
mailing list