Re: time difference - beautify my code

2015-07-03 Thread dd0s via Digitalmars-d-learn

cool, thx for the detailed explanation guys!


time difference - beautify my code

2015-07-02 Thread dd0s via Digitalmars-d-learn
i got a date t described in seconds from 1.1.1970, and i want to 
check if the current time is further than 12 hours from the given 
time t. the following code works but it's super ugly =S


please give me some ideas how to make this code nicer :)

  private static bool sessionIsCurrent(long t)
  {
DateTime dateTime = DateTime(1970, 1, 1) + 
dur!msecs(t*1000);
DateTime curTime = DateTime() + 
dur!hnsecs(Clock.currStdTime());

return (curTime - dateTime)  dur!msecs(1000*60*60*12);
  }

thx for your effort


wrong struct alignment

2015-07-01 Thread dd0s via Digitalmars-d-learn

i have the following struct, and i expect it to have 30 bytes
but sizeof tells me it has 32 bytes. dmd seems to still use 4byte 
alignment altough i specified to align 2bytes.


struct netadr_t {
align(2):
inttype; // 0
intscope_id; // 4
short  port; // 8 // -- this is 4 bytes instead of 2
intsock;   // 10

union {
ubyte[4]ip; // 14
ubyte[10] ipx;
ubyte[16] ip6;
}
}

since i'm interfacing with a c library the struct layout has to 
be equal :(




Re: wrong struct alignment

2015-07-01 Thread dd0s via Digitalmars-d-learn

thank you both, indeed missed that truncation step


Re: using new in shared library causes access violation

2015-06-26 Thread dd0s via Digitalmars-d-learn

On Friday, 26 June 2015 at 16:32:44 UTC, Adam D. Ruppe wrote:
Did you call Runtime.initialized in the D side of that 
initialization fucntion?


No i wasn't aware of that. Thank you so much Adam. I still don't 
know what it does exactly but i just call it when OnPluginInit() 
is called. Are you aware of any resources where i can read up on 
this?

btw bought your D Cookbook, and like it alot :3


if any1 is looking for it
http://dlang.org/phobos/core_runtime.html

import core.runtime;
then call
Runtime.initialize();



using new in shared library causes access violation

2015-06-26 Thread dd0s via Digitalmars-d-learn

hi,

I have a c++ program with a plugin system and i try to write a 
plugin for it.
when the plugin is loaded by the program the extern (C) int 
OnInit() method is called. so far everything works fine. But as 
soon as i try to create a new class instance a segmentation fault 
occurs ( the constructor is empty ).


Here is a screenshot with all the important code
# error message in the left console
# right top the executed code
# right bottom the dub.json i use
http://imgur.com/PfvsAm4

hopefully any1 can make sense of this error :/
thank you for helping