Re: Two questions

2019-01-02 Thread IM via Digitalmars-d-learn

On Wednesday, 2 January 2019 at 17:49:52 UTC, H. S. Teoh wrote:
On Wed, Jan 02, 2019 at 05:38:41PM +, IM via 
Digitalmars-d-learn wrote:

1- How do I do in D the equivalent of the following C++ macro?

#define OUT_VAL(val) (count << #val << " = " << val << endl)

In particular the #val above to the actual macro argument as a 
string?

[...]

Try something along these lines:

import std.stdio;
void OUT_VAL(alias val)() {
writefln("%s = %s", __traits(identifier, val), val);
}
void main() {
int i = 123;
string s = "abc";
OUT_VAL!i;
OUT_VAL!s;
}


T


Thank you so much. Will give this a try.


Re: Two questions

2019-01-02 Thread IM via Digitalmars-d-learn
On Wednesday, 2 January 2019 at 21:56:03 UTC, Steven 
Schveighoffer wrote:

On 1/2/19 12:38 PM, IM wrote:


[...]


With those ... I have to guess.

There are 2 possibilities.

Possibility 1: there is a method named 'doSomeWork' which takes 
at least one parameter. This overrides the UFCS function 
(member functions always win over UFCS).


Possibility 2: All this is actually inside a function or 
unittest. Nested functions cannot participate in UFCS.




Perfect, this was it. Thank you so much. doSomeWork() was nested 
inside a unittest{} block. I didn't know UFCS won't work in this 
case.


Of course, these are guesses. But given the very scant code 
above, I'm not sure I could offer any other suggestions. If 
neither of those is the case, I'd need a working example.


-Steve




Re: Two questions

2019-01-02 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/2/19 12:38 PM, IM wrote:

2- Yesterday I was experimenting with something and I wrote something 
like the following:


struct MyType {
   ...
}

void doSomeWork(ref MyType o) {
    ...
}

auto t = MyType(...);

t.doSomeWork(); // <-- failed to compile.

Why did the above UFCS call fail to compile? I had to do doSomeWork(t) 
instead.


With those ... I have to guess.

There are 2 possibilities.

Possibility 1: there is a method named 'doSomeWork' which takes at least 
one parameter. This overrides the UFCS function (member functions always 
win over UFCS).


Possibility 2: All this is actually inside a function or unittest. 
Nested functions cannot participate in UFCS.


Of course, these are guesses. But given the very scant code above, I'm 
not sure I could offer any other suggestions. If neither of those is the 
case, I'd need a working example.


-Steve


Re: Two questions

2019-01-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 02, 2019 at 05:38:41PM +, IM via Digitalmars-d-learn wrote:
> 1- How do I do in D the equivalent of the following C++ macro?
> 
> #define OUT_VAL(val) (count << #val << " = " << val << endl)
> 
> In particular the #val above to the actual macro argument as a string?
[...]

Try something along these lines:

import std.stdio;
void OUT_VAL(alias val)() {
writefln("%s = %s", __traits(identifier, val), val);
}
void main() {
int i = 123;
string s = "abc";
OUT_VAL!i;
OUT_VAL!s;
}


T

-- 
The easy way is the wrong way, and the hard way is the stupid way. Pick one.


Two questions

2019-01-02 Thread IM via Digitalmars-d-learn

1- How do I do in D the equivalent of the following C++ macro?

#define OUT_VAL(val) (count << #val << " = " << val << endl)

In particular the #val above to the actual macro argument as a 
string?


2- Yesterday I was experimenting with something and I wrote 
something like the following:


struct MyType {
  ...
}

void doSomeWork(ref MyType o) {
   ...
}

auto t = MyType(...);

t.doSomeWork(); // <-- failed to compile.

Why did the above UFCS call fail to compile? I had to do 
doSomeWork(t) instead.


Thank you so much!


C++ Interop -- Two Questions

2015-09-09 Thread Mike Parker via Digitalmars-d-learn

Given a C++ class that looks like this:

class Foo {
   static void Initialize(const SomeObject&);

   virtual void func1();
}

The documentation at [1] doesn't say anything about how to handle 
static member functions like Initialize, nor do I see anything 
about references. I assume I can declare any reference function 
parameters using D's ref, but I have no idea how to declare 
static methods. My questions:


1) Am I right about ref?

2) Do I need to create a wrapper function in C or C++ for static 
member functions?


Re: C++ Interop -- Two Questions

2015-09-09 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 9 September 2015 at 09:55:21 UTC, Mike Parker wrote:


The documentation at [1] doesn't say anything about how to


[1] http://dlang.org/cpp_interface.html


Re: C++ Interop -- Two Questions

2015-09-09 Thread Jacob Carlborg via Digitalmars-d-learn

On 2015-09-09 11:55, Mike Parker wrote:

Given a C++ class that looks like this:

class Foo {
static void Initialize(const SomeObject&);

virtual void func1();
}

The documentation at [1] doesn't say anything about how to handle static
member functions like Initialize, nor do I see anything about
references. I assume I can declare any reference function parameters
using D's ref, but I have no idea how to declare static methods. My
questions:

1) Am I right about ref?


I would assume so. It's just a pointer under the hood.


2) Do I need to create a wrapper function in C or C++ for static member
functions?


The documentation for the C++ support is very outdated. I recommend to 
give it a try and see what happens :). Alternatively look in the DMD 
test suite and see what you can find, or the DMD source code now when 
it's in D.


--
/Jacob Carlborg


Re: C++ Interop -- Two Questions

2015-09-09 Thread Kagamin via Digitalmars-d-learn
Static functions are declared with `static` storage class. This 
looks so basic, it's even not documented in language spec, lol.


In D classes are reference types by default.


Re: C++ Interop -- Two Questions

2015-09-09 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 9 September 2015 at 11:49:33 UTC, Kagamin wrote:
Static functions are declared with `static` storage class. This 
looks so basic, it's even not documented in language spec, lol.




Yes, I get that. But how does that work when you're linking to a 
C++ library and the translation of the C++ class to D is an 
interface? Or is it possible now to link D classes directly with 
C classes?



In D classes are reference types by default.


Yes, of course. I just want to verify that the D ref and C++ ref 
are equivalent.


I realize I can do it myself when I sit down this weekend and 
start exploring it, but I'm hoping someone can point me to a blog 
post, some sample code, or just give me some insights to save 
time.


Re: C++ Interop -- Two Questions

2015-09-09 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 9 September 2015 at 13:17:53 UTC, Mike Parker wrote:
Yes, I get that. But how does that work when you're linking to 
a C++ library and the translation of the C++ class to D is an 
interface? Or is it possible now to link D classes directly 
with C classes?


Classes and templates except for special members (which are 
usually relied upon heavily in C++ code, but maybe your C++ code 
is unusual).


I realize I can do it myself when I sit down this weekend and 
start exploring it, but I'm hoping someone can point me to a 
blog post, some sample code, or just give me some insights to 
save time.


You can see bugzilla issues marked with C++ keyword. The docs 
were deemed unworthy because of skills required to write C++ 
bindings. Maybe because it's still not practical as it doesn't 
support critical C++ idioms like RAII.


Re: two questions on enums

2014-04-04 Thread Chris Williams

On Thursday, 3 April 2014 at 23:16:14 UTC, Eric wrote:
Okay - I'm new to D, and I'm comming from a java background.  
Suppose
you are designing an API, and you want the user to supply 
arguments
as an enum.  But the user needs to define the enum, so how can 
the API
know in advance what enum to require?  The solution is to 
require an
enum that implements a known interface.  This is easy to do in 
java,
but I haven't yet tried it in D.  I suspect it could be done 
with CTFE
or something.  An example where I use this is for electronics 
software.
If I need the user to supply a set of pins, the pins are 
supplied as an
enum which implements an interface.  By using the interface, it 
also
forces the user to include all of the attributes of each pin 
such as
direction, max load, DC current, etc.  Since class type enums 
are references,
they are light, - and they should be immutable - so they are 
thread safe aslo.


I'm not sure how you're using your enum. In Java, the only way to 
perform a switch over an enum is if you know all the values 
during compile time. Passing a type Enum into a function (i.e. as 
opposed to enum MyEnumType') requires using introspection to 
pull the actual values out, and then a loop to scan through them 
for your target value.


But if you've programmed a switch for a known enum type, then 
that means the enum has already been implemented and there is no 
chance for more than one type to be passed in.


So I'm confused.


Re: two questions on enums

2014-04-04 Thread Eric

By using the interface,

it also
forces the user to include all of the attributes of each pin 
such as
direction, max load, DC current, etc.  Since class type enums 
are references,
they are light, - and they should be immutable - so they are 
thread safe aslo.


I'm not sure how you're using your enum. In Java, the only way 
to perform a switch over an enum is if you know all the values 
during compile time. Passing a type Enum into a function (i.e. 
as opposed to enum MyEnumType') requires using introspection 
to pull the actual values out, and then a loop to scan through 
them for your target value.


But if you've programmed a switch for a known enum type, then 
that means the enum has already been implemented and there is 
no chance for more than one type to be passed in.


So I'm confused.


I guess D does not see enums as enums, but rather as whatever
type the enum happens to implement. In java, all enums are
of enum type.  So it's probably me that's confused.

-Eric




two questions on enums

2014-04-03 Thread Eric


1).  Is there a way to import an enum so that you don't need
to qualify each instance with the type name?  Something like
java does with its static import.

2).  It seems that you can't use an enum of struct or class type
in a switch statement.  This seems inconsistent.  Would it make
sense to have like an uint opOrdinal() method that would return
a value known at compile time so that class or struct enums
can be used in switch statements?

Thanks,

Eric


Re: two questions on enums

2014-04-03 Thread bearophile

Eric:


1).  Is there a way to import an enum so that you don't need
to qualify each instance with the type name?  Something like
java does with its static import.


In some cases you can use the handy with() statement for that 
purpose.


One example usages:

final switch (foo) with (MyEnum) {
...
}



2).  It seems that you can't use an enum of struct or class type
in a switch statement.


Using an enumeration of class instances isn't a good idea, they 
are designed mostly for integral built-in types, including chars, 
etc.


Regarding your enhancement, look here (I suggest an unapply as in 
Scala), you can even vote it:

https://d.puremagic.com/issues/show_bug.cgi?id=596

Bye,
bearophile


Re: two questions on enums

2014-04-03 Thread Eric




In some cases you can use the handy with() statement for that 
purpose.


One example usages:

final switch (foo) with (MyEnum) {
...
}


Okay - the with statement may help in some cases. I'll
have to try it out...




Using an enumeration of class instances isn't a good idea, they 
are designed mostly for integral built-in types, including 
chars, etc.




I disagree. If you just think of a class type enum as a class 
type,

then what you say makes sense.  But if you instead think of it as
a more powerful enum then it can enhance data safety in a program.

-Eric





Re: two questions on enums

2014-04-03 Thread bearophile

Eric:

I disagree. If you just think of a class type enum as a class 
type,
then what you say makes sense.  But if you instead think of it 
as a more powerful enum then it can enhance data safety in a 
program.


I was speaking about the current D enum, as implemented and as 
designed. Regarding your enhancements, I need some examples or a 
better explanation to understand your point.


Bye,
bearophile


Re: two questions on enums

2014-04-03 Thread Eric

On Thursday, 3 April 2014 at 22:34:19 UTC, bearophile wrote:

Eric:

I disagree. If you just think of a class type enum as a class 
type,
then what you say makes sense.  But if you instead think of it 
as a more powerful enum then it can enhance data safety in a 
program.


I was speaking about the current D enum, as implemented and as 
designed. Regarding your enhancements, I need some examples or 
a better explanation to understand your point.




Okay - I'm new to D, and I'm comming from a java background.  
Suppose
you are designing an API, and you want the user to supply 
arguments
as an enum.  But the user needs to define the enum, so how can 
the API
know in advance what enum to require?  The solution is to require 
an
enum that implements a known interface.  This is easy to do in 
java,
but I haven't yet tried it in D.  I suspect it could be done with 
CTFE
or something.  An example where I use this is for electronics 
software.
If I need the user to supply a set of pins, the pins are supplied 
as an
enum which implements an interface.  By using the interface, it 
also
forces the user to include all of the attributes of each pin such 
as
direction, max load, DC current, etc.  Since class type enums are 
references,
they are light, - and they should be immutable - so they are 
thread safe aslo.


I hope this example illustrates where I'm comming from.

-Eric




Re: Two Questions about Linking to C libraries

2013-11-27 Thread Craig Dillabaugh
On Wednesday, 27 November 2013 at 07:30:58 UTC, Jacob Carlborg 
wrote:

On 2013-11-27 02:26, Craig Dillabaugh wrote:

2. Once I think my bindings are stable I would like to add 
them to
Deimos or DUB registries.  Are there any recommendations for 
testing
bindings? I checked through some other bindings on GitHub and 
didn't see
any unit tests or the like. Are there any 'best practices' out 
there for

testing bindings?


I don't think there's an easy way to do unit testing for 
bindings. What you could do is port the original unit tests if 
available. Or create some new unit tests if none exists.


Thanks.  There were no unit tests with the original code. I will 
take a shot at it.


Two Questions about Linking to C libraries

2013-11-26 Thread Craig Dillabaugh

I recently created bindings to the C libary shapelib.

http://shapelib.maptools.org/

I generated my own bindings by hand, and another set of bindings 
with DStep.


I created a small test program to test my bindings.  My current 
test program in its entirety is:


import std.stdio;
import std.string;
import std.conv;

import shapefil;

int main( string args[] )
{
  const char* filename = std.string.toStringz( args[1] );

  SHPHandle hShp = SHPOpen(filename, rb);

  int num_entities;
  int shp_type;
  double pad_min_bound;
  double pad_max_bound;

  SHPGetInfo( hShp, num_entities, shp_type,
  pad_min_bound, pad_max_bound);

  writeln(Shapefile contains  ~ to!string(num_entities) ~  
entities.);

  writeln(Of type  ~ to!string( SHPTypeName( shp_type) ));
  writeln(Bounds = [ ~to!string(pad_min_bound) ~ ,
   ~ to!string(pad_max_bound) ~ ]);

   SHPClose( hShp );
   return 0;
}

It simply reads a Shape File, the name for which is passed from 
the command line.


When I execute this I get the following message:

./shapetest data/dresden/gis.osm_water_v06.shp
Shapefile contains 799 entities.
Of type Polygon
Bounds = [13.5274,50.9632]
Segmentation fault

The first three lines output are what I expected, but then it 
segfaults on exit.

Running it in GDB I get the following error message:

Program received signal SIGSEGV, Segmentation fault.
0x00443fc7 in rt.dmain2._d_run_main() ()

Printing the backtrace provides no additional information.  The 
same problem occurs whether I used my hand-rolled binds or the 
DStep version.


So my two questions are:

1. Does anyone have any idea why my program is segfaulting. It 
seems to crash at exit and I read somewhere (can't recall where) 
that uncollected C style strings may cause the GC to fail.  
Perhaps this is my problem.  I tried commenting out some of the 
statements (eg. the SHPTypeName( shp_type) line, which returns a 
const char *, but I still get a segfault.  Any ideas on how to 
find the root cause?


2. Once I think my bindings are stable I would like to add them 
to Deimos or DUB registries.  Are there any recommendations for 
testing bindings? I checked through some other bindings on GitHub 
and didn't see any unit tests or the like. Are there any 'best 
practices' out there for testing bindings?





Re: Two Questions about Linking to C libraries

2013-11-26 Thread Jesse Phillips
Don't have answers. Do you still get segfault removing SHPClose( 
hShp );


Other comment:



  writeln(Bounds = [ ~to!string(pad_min_bound) ~ ,
   ~ to!string(pad_max_bound) ~ ]);


writeln(Bounds = [, pad_min_bound, ,, pad_max_bound, ]);


Re: Two Questions about Linking to C libraries

2013-11-26 Thread Craig Dillabaugh
On Wednesday, 27 November 2013 at 02:36:01 UTC, Jesse Phillips 
wrote:
Don't have answers. Do you still get segfault removing 
SHPClose( hShp );

Yep.



Other comment:



 writeln(Bounds = [ ~to!string(pad_min_bound) ~ ,
  ~ to!string(pad_max_bound) ~ ]);


writeln(Bounds = [, pad_min_bound, ,, pad_max_bound, 
]);

Thanks, thats look a bit nicer.


Re: Two Questions about Linking to C libraries

2013-11-26 Thread Jacob Carlborg

On 2013-11-27 02:26, Craig Dillabaugh wrote:


2. Once I think my bindings are stable I would like to add them to
Deimos or DUB registries.  Are there any recommendations for testing
bindings? I checked through some other bindings on GitHub and didn't see
any unit tests or the like. Are there any 'best practices' out there for
testing bindings?


I don't think there's an easy way to do unit testing for bindings. What 
you could do is port the original unit tests if available. Or create 
some new unit tests if none exists.


--
/Jacob Carlborg


Re: Two questions about assignments

2013-05-28 Thread bearophile

I will add it to Bugzilla then, if it's not already there.


http://d.puremagic.com/issues/show_bug.cgi?id=10192

Bye,
bearophile


Two questions about assignments

2013-05-27 Thread bearophile
Do you know if it's OK to accept x3 assignment and refuse the a2 
assignment?



struct Foo {
immutable(char)[4] bar;
}
Foo x1 = { AA };// No error.
immutable(char)[4] a1 = AA; // No error.
void main() {
Foo x2 = { AA };// No error.
Foo x3 = Foo(AA);   // No error.
immutable(char)[4] a2 = AA; // Error: lengths don't match
  // for array copy, 4 = 2
}

-

This is a recent change in std.typecons.tuples:

// 
https://github.com/9rnsr/phobos/commit/fdcaba7226c978f281f2d237fc772c6d7913eaf3



But from this test they don't seem to be one a subtype of the 
other:



import std.typecons: Tuple;
void main() {
alias T1 = Tuple!(int, int);
alias T2 = Tuple!(int,x, int,y);
auto t1 = T1(10, 20);
auto t2 = T2(100, 200);
t1 = t2; // OK.
t2 = t1; // OK?
}


Bye and thank you,
bearophile


Re: Two questions about assignments

2013-05-27 Thread Kenji Hara

On Monday, 27 May 2013 at 18:00:38 UTC, bearophile wrote:
Do you know if it's OK to accept x3 assignment and refuse the 
a2 assignment?



struct Foo {
immutable(char)[4] bar;
}
Foo x1 = { AA };// No error.
immutable(char)[4] a1 = AA; // No error.
void main() {
Foo x2 = { AA };// No error.
Foo x3 = Foo(AA);   // No error.
immutable(char)[4] a2 = AA; // Error: lengths don't match
  // for array copy, 4 = 2
}


This is known static array initializing inconsistency between 
DeclDefs scope and statement scope. I think it is a bug.



-

This is a recent change in std.typecons.tuples:

// 
https://github.com/9rnsr/phobos/commit/fdcaba7226c978f281f2d237fc772c6d7913eaf3



But from this test they don't seem to be one a subtype of the 
other:



import std.typecons: Tuple;
void main() {
alias T1 = Tuple!(int, int);
alias T2 = Tuple!(int,x, int,y);
auto t1 = T1(10, 20);
auto t2 = T2(100, 200);
t1 = t2; // OK.
t2 = t1; // OK?
}


std.typecons.Tuple supports structural assignment before the 
change.

The code also works with 2.062.

Kenji Hara


Re: Two questions about assignments

2013-05-27 Thread bearophile

Kenji Hara:

Thank you very much for your gentle and useful answers :-)



struct Foo {
   immutable(char)[4] bar;
}
Foo x1 = { AA };// No error.
immutable(char)[4] a1 = AA; // No error.
void main() {
   Foo x2 = { AA };// No error.
   Foo x3 = Foo(AA);   // No error.
   immutable(char)[4] a2 = AA; // Error: lengths don't match
 // for array copy, 4 = 2
}


This is known static array initializing inconsistency between 
DeclDefs scope and statement scope. I think it is a bug.


I will add it to Bugzilla then, if it's not already there.

(By the way, in my opinion the D compiler should see as bugs all 
those 5 cases, as explained in Issue 3849, because when I specify 
the array length I do it also for safety, to be sure the literal 
gives me exactly that number of chars. This is useful for tables 
and data represented as strings of chars.)







-

This is a recent change in std.typecons.tuples:

// 
https://github.com/9rnsr/phobos/commit/fdcaba7226c978f281f2d237fc772c6d7913eaf3



But from this test they don't seem to be one a subtype of the 
other:



import std.typecons: Tuple;
void main() {
   alias T1 = Tuple!(int, int);
   alias T2 = Tuple!(int,x, int,y);
   auto t1 = T1(10, 20);
   auto t2 = T2(100, 200);
   t1 = t2; // OK.
   t2 = t1; // OK?
}


std.typecons.Tuple supports structural assignment before the 
change.

The code also works with 2.062.


I know it's not a regression. But you say:
Named-field tuple should be a subtype of unnamed-field tuple.

You can have sub-typing, or you can have structural typing, but 
mixing the two silently seems a mess.


Also in your test cases of that commit fdcaba7226c... there is:

+Tuple!(int, int)[] arr;
+arr ~= tuple(10, 20); // OK
+arr ~= Tuple!(int, x, int, y)(10, 20); // NG - OK

If I try to do the opposite, that is to append a tuple(10, 20) to 
an array of tuples with named fields, I get an error:


import std.typecons;
void main() {
Tuple!(int, x, int, y)[] arr;
arr ~= tuple(10, 20); // Error.
}


So here there is a true sub-typing. So sometimes tuples with 
named fields are sub-types and in other situations they act in a 
structural typing way. I think this mix of behaviours is a little 
confusing.


Bye,
bearophile


Re: Two questions about assignments

2013-05-27 Thread Kenji Hara

On Tuesday, 28 May 2013 at 00:29:04 UTC, bearophile wrote:
std.typecons.Tuple supports structural assignment before the 
change.

The code also works with 2.062.


I know it's not a regression. But you say:
Named-field tuple should be a subtype of unnamed-field tuple.

You can have sub-typing, or you can have structural typing, but 
mixing the two silently seems a mess.


Also in your test cases of that commit fdcaba7226c... there is:

+Tuple!(int, int)[] arr;
+arr ~= tuple(10, 20); // OK
+arr ~= Tuple!(int, x, int, y)(10, 20); // NG - OK

If I try to do the opposite, that is to append a tuple(10, 20) 
to an array of tuples with named fields, I get an error:


import std.typecons;
void main() {
Tuple!(int, x, int, y)[] arr;
arr ~= tuple(10, 20); // Error.
}


So here there is a true sub-typing. So sometimes tuples with 
named fields are sub-types and in other situations they act in 
a structural typing way. I think this mix of behaviours is a 
little confusing.


Basically Tuple would follow structural typing. Even if it is 
impossible, it would follow true subtyping right now. That's the 
purpose of my change.


Kenji Hara


Re: Two questions about %a

2011-03-04 Thread Magnus Lie Hetland

On 2011-03-04 03:16:50 +0100, Nick Sabalausky said:

I'm no floating-point expert, but I would think that the only way to 
get an exact representation would be to output the raw data in hex (or 
binary, or octal, etc):


writef(0x%X, cast(ulong)1.2);


That's also an option, certainly. Then I could just write it as a 
decimal integer, I guess.


But the point of hex-literals for floats is precicely that they can 
represent floats exactly (even though it may not *look* like it, as in 
this case, because lots of digits are required to approximate the 
decimal value 1.2). So using those shold be safe -- and perhaps more 
easily read on other platforms, for example (byte order), or into 
floats with other precisions or the like.


Thanks for the suggestion, though :)

--
Magnus Lie Hetland
http://hetland.org



Re: Two questions about %a

2011-03-03 Thread Nick Sabalausky
Lars T. Kyllingstad public@kyllingen.NOSPAMnet wrote in message 
news:iknfsh$13ga$1...@digitalmars.com...
 On Wed, 02 Mar 2011 13:35:11 +0100, Magnus Lie Hetland wrote:

 First question: I just noticed that writefln(%a, 1.2) writes
 0x1.3p+0, while writeln(format(%a, 1.2)) (that is, with
 std.string.format) writes 0x9.8p-3 ... wouldn't it be nice
 to be consistent here? (The former is what printf in gcc gives.) Or am I
 missing a difference in functionality?

 Hm, that's weird.  I'm pretty sure writefln() is doing the right thing
 here, since that's what printf() does.  I've had a look at the code for
 format(), and it looks to me like it is using some old formatting code
 that is being phased out.


Yea, definitely seems to be the case. Unless it's been fixed recently, 
format doesn't even support the posix-style positional argument specifiers 
that were added to writef ages ago (I know I filed a ticket on this, but I 
don't recall the number offhand).

 Second question: Just to make sure, this *is* an exact representation of
 the underlying floating-point number? (I.e., if that'w what I'm after,
 using %a *is* the way to go?)

 Yes, that's right.


I'm no floating-point expert, but I would think that the only way to get an 
exact representation would be to output the raw data in hex (or binary, or 
octal, etc):

writef(0x%X, cast(ulong)1.2);





Two questions about %a

2011-03-02 Thread Magnus Lie Hetland
First question: I just noticed that writefln(%a, 1.2) writes 
0x1.3p+0, while writeln(format(%a, 1.2)) (that is, with 
std.string.format) writes 0x9.8p-3 ... wouldn't it be nice 
to be consistent here? (The former is what printf in gcc gives.) Or am 
I missing a difference in functionality?


Second question: Just to make sure, this *is* an exact representation 
of the underlying floating-point number? (I.e., if that'w what I'm 
after, using %a *is* the way to go?)


--
Magnus Lie Hetland
http://hetland.org



Re: Two questions about %a

2011-03-02 Thread Lars T. Kyllingstad
On Wed, 02 Mar 2011 13:35:11 +0100, Magnus Lie Hetland wrote:

 First question: I just noticed that writefln(%a, 1.2) writes
 0x1.3p+0, while writeln(format(%a, 1.2)) (that is, with
 std.string.format) writes 0x9.8p-3 ... wouldn't it be nice
 to be consistent here? (The former is what printf in gcc gives.) Or am I
 missing a difference in functionality?

Hm, that's weird.  I'm pretty sure writefln() is doing the right thing 
here, since that's what printf() does.  I've had a look at the code for 
format(), and it looks to me like it is using some old formatting code 
that is being phased out.  I've created a bug report for this, and will 
look into fixing it shortly:

  http://d.puremagic.com/issues/show_bug.cgi?id=5687


 Second question: Just to make sure, this *is* an exact representation of
 the underlying floating-point number? (I.e., if that'w what I'm after,
 using %a *is* the way to go?)

Yes, that's right.

-Lars


Re: Two questions about converting a C header file

2010-09-24 Thread Sean Kelly
Juanjo Alvarez Wrote:

 Hi,
 
 I'm converting a C header file but there are two things left:
 
 1. If the header file contains some D reserved word (in my case, in and 
 out in a struct) what is the best way to workaround it? Do you write 
 another C file and link about it?

The convention I use for reserved words is to append an underscore to the word. 
 So code may need to be changed a bit, but it's as close as possible to the 
original.

 2. What about va_list?

If I'm following you correctly, see core.stdc.stdarg.


Two questions about converting a C header file

2010-09-23 Thread Juanjo Alvarez
Hi,

I'm converting a C header file but there are two things left:

1. If the header file contains some D reserved word (in my case, in and 
out in a struct) what is the best way to workaround it? Do you write 
another C file and link about it?

2. What about va_list?


Re: Two questions about converting a C header file

2010-09-23 Thread Juanjo Alvarez
Auto reply, found both:

1. Just rename the varname, stupid stupid stupid!

2. import std.c.stdarg

On Thu, 23 Sep 2010 19:44:44 +, Juanjo Alvarez wrote:

 Hi,
 
 I'm converting a C header file but there are two things left:
 
 1. If the header file contains some D reserved word (in my case, in
 and out in a struct) what is the best way to workaround it? Do you
 write another C file and link about it?
 
 2. What about va_list?