Re: Deleting a file with extsion *.FIFO in Windows

2018-06-01 Thread Dlang User via Digitalmars-d-learn

On 6/1/2018 12:06 AM, vino.B wrote:

On Thursday, 24 May 2018 at 11:31:15 UTC, bauss wrote:

On Thursday, 24 May 2018 at 06:59:47 UTC, Vino wrote:

Hi All,

  Request your help on how to delete a file which has the extension 
.fifo (.javast.fifo) in Windows.


From,
Vino.B


What exactly is your issue with it?


Hi Bauss,

  We have a java program which creates a file with extension .fifo and 
we have another program written in D to clean up the old file, so the D 
code is not able to delete these files using any of the D function 
provided it states "Access Denied" we tried to provide the full access 
manually even then it is not able to delete such files.


From,
Vino.B


Are the files by chance marked as read only (when you right click on a 
.fifo file and select properties)?


Re: property += operator

2018-05-10 Thread Dlang User via Digitalmars-d-learn

On 5/10/2018 3:18 PM, Ali Çehreli wrote:

On 05/10/2018 01:03 PM, Dlang User wrote:

 >> this didn´t work either.
 >> note that 'f.data+= 2;' don't call the write property
 >
 > That's odd, it works on my machine (Windows 10 with V2.079.0 DMD 
compiler).


Try putting writeln expressions in the two functions to see which one 
gets called. ;)


Ali



Now, I see the problem. Sorry for the noise.




Re: property += operator

2018-05-10 Thread Dlang User via Digitalmars-d-learn

On 5/10/2018 2:50 PM, SrMordred wrote:

On Thursday, 10 May 2018 at 19:41:41 UTC, Dlang User wrote:

On 5/10/2018 1:43 PM, SrMordred wrote:

[...]


I am relatively new to D and I was under the impression that that was 
a limitation of @property functions.


But, re-reading the language reference, it gave this example (it 
returns something from the write property, which seems odd), I 
modified to add refs, and then it seems to work, but I am not sure if 
it is correct or not:


import std.stdio;

struct Foo
{
    @property ref int data() { return m_data; } // read property

    @property ref int data(int value) { return m_data = value; } // 
write property


  private:
    int m_data;
}

void main()
{
Foo f;
f.data = 5;
f.data++;
f.data+= 2;
writeln(f.data);

}


this didn´t work either.
note that 'f.data+= 2;' don't call the write property


That's odd, it works on my machine (Windows 10 with V2.079.0 DMD 
compiler).


I changed main to this:

void main()
{
Foo f;
writeln(f.data);
f.data = 5;
writeln(f.data);
f.data++;
writeln(f.data);
f.data+= 2;
writeln(f.data);
}


and then I get this output:

0
5
6
8



Re: property += operator

2018-05-10 Thread Dlang User via Digitalmars-d-learn

On 5/10/2018 1:43 PM, SrMordred wrote:

struct T
{
     int x;
     @property ref X(){ return x; }
     @property X(int v)
     {
     x = v;
     }
}

T t;
t.X += 10;

The setter 'x = v' are not executed because i´m returning the reference 
of x.

And without the 'ref' the compiler complains because 'x' is not a lvalue.

Any solution to make it work like native arr.length+=10 works?

( I Thought on returning a struct with "+=" operator but it is a strange 
solution )


I am relatively new to D and I was under the impression that that was a 
limitation of @property functions.


But, re-reading the language reference, it gave this example (it returns 
something from the write property, which seems odd), I modified to add 
refs, and then it seems to work, but I am not sure if it is correct or not:


import std.stdio;

struct Foo
{
@property ref int data() { return m_data; } // read property

@property ref int data(int value) { return m_data = value; } // 
write property


  private:
int m_data;
}

void main()
{
Foo f;
f.data = 5;
f.data++;
f.data+= 2;
writeln(f.data);

}



Re: signbit question

2018-03-15 Thread Dlang User via Digitalmars-d-learn

On 3/15/2018 12:39 PM, Miguel L wrote:

On Thursday, 15 March 2018 at 17:31:38 UTC, rumbu wrote:

On Thursday, 15 March 2018 at 17:18:08 UTC, Miguel L wrote:

On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote:

On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote:

[...]


integers don't have a sign-bit.
since they are not necessarily singed.
However if an integer is signed and using 1-complement
you can either do sign = var < 0 or
sign = (var & (1 << (sizeof(var)*8 - 1));
though I cannot tell which one is faster you have to experiment.


Thanks. Just one more question:

Is this code correct? I don't care about +0 or -0 as the calculations 
on f guarantee it cannot be 0 at all.


int a;
float f;

if((a<0)==signbit(f)) {}
else {...}


If you are comparing with an integer, please avoid signbit. It will 
return 1 also for -0.0, -inf and -nan.


Don't bother also with signbit for integer types. The compiler usually 
outsmarts the programmer in finding the best way to compare an integer 
with 0.


You can simply write:

if (a < 0 && f < 0) {...}

This will cover the [-inf..0) but not the NaN case. You can test it in 
a separate branch


if (isNaN(f)) {...}


There are various in my code there are more than two variables, and i'd 
like to check when their signs differ.I am trying to avoid this, maybe 
there is no point in it:


if(!((a>=0 && f>=0) || (a<0 && f<0))){
//signs are different

}

Thanks, anyway


You could simplify that to this:

if ((a < 0) != (f < 0))
{

}

Or if you have more than two variables you could do something like this:

bool AllSameSign(double[] args ...)
{
  //Only need to check if there are more than one of them
  if (args.length > 1)
  {
//Compare arg[0] to all the other args.
for (int i = 1; i < args.length; i++)
{
  if ((args[0] < 0) != (args[i] < 0))
  {
return false;
  }
}
  }
  return true;
}

Which you could call like this, with as many variables as you like:

AllSameSign(a,f);




Re: fPIC Error

2016-11-03 Thread dlang user via Digitalmars-d-learn
On Thursday, 3 November 2016 at 06:11:48 UTC, rikki cattermole 
wrote:
Took me a while to replicate your build environment but it 
looks like a false alarm.


rikki@debian:/tmp/test$ dmd test.d
rikki@debian:/tmp/test$ file test
test: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), 
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, 
for GNU/Linux 2.6.32, 
BuildID[sha1]=0a6394b9ec9b82e07440ab62cd71932f0ab568d1, not 
stripped


rikki@debian:/tmp/test$ ./test
Edit source/app.d to start your project.

rikki@debian:/tmp/test$ cat /etc/dmd.conf
;
; dmd.conf file for dmd
;
; dmd will look for dmd.conf in the following sequence of 
directories:

;   - current working directory
;   - directory specified by the HOME environment variable
;   - directory dmd resides in
;   - /etc directory
;
; Names enclosed by %% are searched for in the existing 
environment and inserted

;
; The special name %@P% is replaced with the path to this file
;

[Environment32]
DFLAGS=-I/usr/include/dmd/phobos 
-I/usr/include/dmd/druntime/import -L-L/usr/lib/i386-linux-gnu 
-L--export-dynamic -fPIC -defaultlib=libphobos2.so


[Environment64]
DFLAGS=-I/usr/include/dmd/phobos 
-I/usr/include/dmd/druntime/import 
-L-L/usr/lib/x86_64-linux-gnu -L--export-dynamic -fPIC 
-defaultlib=libphobos2.so


Thanks for looking at it and confirming you are seeing the same 
thing.


I am no expert, but after some additional research I think I see 
what is going on.  From what I read the gcc -fPIC option creates 
a shared library, while gcc -fPIE option creates an executable.  
You can also create a dual purpose file that is a shared library 
and is also executable by creating a shared library if that file 
also contains a main function (that might be oversimplified a 
little bit).


Looking at the dmd documentation, it only has a -fPIC option, 
there is no -fPIE option, which has the following description:


generate Position Independent Code (which is used for building 
shared libraries).


So, if I am understanding everything correctly because dmd only 
has -fPIC, the only option is to create a dual purpose file that 
is both a shared library and executable.


fPIC Error

2016-11-02 Thread Dlang User via Digitalmars-d-learn
I am running Debian Testing and I think I have run into the 
recent fPIC issue.  This is the source code for the test project 
I am using:


import std.stdio;

void main()
{
writeln("Edit source/app.d to start your project.");
readln();
}


When I try to compile a project, I get the following errors 
(truncated for brevity):



/usr/bin/ld: 
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libphobos2.a(thread_26c_155.o): relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not be used when making a shared object; recompile with -fPIC

/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
dmd failed with exit code 1.
Exit code 2
Build complete -- 1 error, 0 warnings

I followed the advice to add "-defaultlib=libphobos2.so -fPIC" to 
my dmd.conf file as a workaround.


This causes it to build without errors, but now the resulting 
executable is marked as a shared library:


Output of the file command:

fpictest: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), 
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for 
GNU/Linux 2.6.32, 
BuildID[sha1]=e83ac1d5dea9e78912a6175d3c1c54b50b4e29cd, not 
stripped


Is this a known issue with this workaround or is there some other 
setting that I need to change?