On Sunday, 25 June 2017 at 02:05:35 UTC, unleashy wrote:
How would I call `addToBar` from C code?
You don't. Instead write it like:
struct Foo
{
int bar;
}
extern(C) void addToBar(Foo* foo, int what) {
foo.bar += what;
}
Then define it in C the same way and you call it the
Hello! If I have a D struct like:
struct Foo
{
int bar;
void addToBar(int what) {
bar += what;
}
}
How would I call `addToBar` from C code? Would I need to put the
`addToBar` function outside of the struct and mark it as `extern
(C)` and in normal D code take advantage of
On Saturday, 24 June 2017 at 21:41:22 UTC, Moritz Maxeiner wrote:
Hi, unfortunately not:
- Operator overloading is supported via member functions only
[1].
- Corollary: You cannot overload operators for builtin types
(i.e. where the cast gets rewritten to `e.opOverloaded` where
`e` is a
On Saturday, 24 June 2017 at 21:11:13 UTC, Igor Shirkalin wrote:
Is it possible without such a constructor?
No. Also, the above works because of the following [1]:
Casting a value v to a struct S, when value is not a struct of
the same type, is equivalent to: `S(v)`
[1]
On Saturday, 24 June 2017 at 20:43:48 UTC, Igor Shirkalin wrote:
I'm in trouble with opCast function.
Is it possible to cast some (integral) type to user defined
structure?
Hi, unfortunately not:
- Operator overloading is supported via member functions only [1].
- Corollary: You cannot
On Saturday, 24 June 2017 at 20:43:48 UTC, Igor Shirkalin wrote:
struct A
{
void * data; // void * type is just for example
// no matter what is here
}
I know that if I add constructor this(int)
struct A {
void * p;
this(int k) { p = cast(void*)k; }
}
auto a = cast(A)
Hello!
I'm in trouble with opCast function.
Is it possible to cast some (integral) type to user defined
structure?
We have a structure:
struct A
{
void * data; // void * type is just for example
// no matter what is here
}
How can we define opCast operator to make the following
On Saturday, 24 June 2017 at 18:46:06 UTC, ketmar wrote:
Petar Kirov [ZombineDev] wrote:
Oh, I should have mentioned that I don't expect anything but
ugly platform-specific hacks possibly involving the object
file format ;)
Just enough of them to claim that the solution is somewhat
Petar Kirov [ZombineDev] wrote:
Oh, I should have mentioned that I don't expect anything but ugly
platform-specific hacks possibly involving the object file format ;)
Just enough of them to claim that the solution is somewhat cross-platform
:D
i guess you can loot at how TSL scanning is done
On Sat, 2017-06-24 at 18:04 +, FoxyBrown via Digitalmars-d-learn
wrote:
> Is it possible? Using LDC or GCC? I do not need any libraries,
> druntime, etc. Just bare bones with the nice D meta
> features(templates, etc).
Sorry but this is an ill-defined wish list. 8051 processors about in
the
On Saturday, 24 June 2017 at 18:05:55 UTC, ketmar wrote:
Petar Kirov [ZombineDev] wrote:
***
But in any case, the null-terminated string was just an
example application.
I'm interested in a fast way to determine the "storage class"
of the memory
a slice or a pointer point to. I'm expecting
Petar Kirov [ZombineDev] wrote:
***
But in any case, the null-terminated string was just an example
application.
I'm interested in a fast way to determine the "storage class" of the
memory
a slice or a pointer point to. I'm expecting some magic along the lines of
checking the range of
Is it possible? Using LDC or GCC? I do not need any libraries,
druntime, etc. Just bare bones with the nice D meta
features(templates, etc).
On Saturday, 24 June 2017 at 14:18:33 UTC, ketmar wrote:
with the edge case when something like the code i posted below
managed to make `a` perfectly aligned with r/o area, and you
got segfault by accising out-of-bounds byte.
BTW, are you sure? AFAIU, it doesn't matter if the CTFE engine
On Saturday, 24 June 2017 at 08:08:33 UTC, ketmar wrote:
Meta wrote:
So I have no clue what I'm doing wrong. This is driving me
insane.
h. known $#^#$@^@%.
enum SymName = ().stringof[2..$]; // this, instead of
symbol.stringof
dirty hack, let's hope that DMD devs won't change
On 6/24/17 10:32 AM, Honey wrote:
On Saturday, 24 June 2017 at 12:41:47 UTC, Steven Schveighoffer wrote:
Any padding bits between fields should be 0 as long as the struct is
initialized (i.e. as long as you don't do Struct s = void).
Padding bits after the fields I assume would be 0, but I
On Saturday, 24 June 2017 at 14:03:16 UTC, Adam D. Ruppe wrote:
On Saturday, 24 June 2017 at 12:41:47 UTC, Steven Schveighoffer
wrote:
There is no spec for this, but I know that when the compiler
has to fill gaps with something it chooses 0.
I'm almost certain there at least used to be a spec
On Saturday, 24 June 2017 at 14:03:16 UTC, Adam D. Ruppe wrote:
On the other hand though, the zero padding requirement does
simplify equality to being memcmp.
That's the reason for my question.
On Saturday, 24 June 2017 at 12:41:47 UTC, Steven Schveighoffer
wrote:
Any padding bits between fields should be 0 as long as the
struct is initialized (i.e. as long as you don't do Struct s =
void).
Padding bits after the fields I assume would be 0, but I don't
know if this is defined. It's
ketmar wrote:
p.s.: btw, druntime tries to avoid that edge case by not checking for
trailing out-of-bounds zero if string ends exactly on dword boundary. it
will miss some strings this way, but otherwise it is perfectly safe.
oops. not druntime, phobos, in `std.string.toStringz()`.
p.s.: btw, druntime tries to avoid that edge case by not checking for
trailing out-of-bounds zero if string ends exactly on dword boundary. it
will miss some strings this way, but otherwise it is perfectly safe.
Petar Kirov [ZombineDev] wrote:
Please note that not all static immutable strings have to be null
terminated.
It is possible to generate a string at ctfe which may appear the same as
string literal, but does not have the \0 at the end.
But in that case, the check `s.ptr[s.length] == 0` in
On Saturday, 24 June 2017 at 13:11:02 UTC, Stefan Koch wrote:
On Saturday, 24 June 2017 at 12:22:54 UTC, Petar Kirov
[ZombineDev] wrote:
[ ... ]
/**
* Returns:
* A pointer to a null-terminated string in O(1) time,
* (with regards to the length of the string and the required
* memory, if
On Saturday, 24 June 2017 at 02:52:23 UTC, Felix wrote:
I'm trying to read in just the first part of a .png file to
peek at it's width and height without loading in the whole
file. I'm using FreeImage for reading the whole file but since
it doesn't have a function to let me peek at the image
On Saturday, 24 June 2017 at 12:41:47 UTC, Steven Schveighoffer
wrote:
There is no spec for this, but I know that when the compiler
has to fill gaps with something it chooses 0.
I'm almost certain there at least used to be a spec for this,
because I remember citing a link to someone who then
On Saturday, 24 June 2017 at 12:22:54 UTC, Petar Kirov
[ZombineDev] wrote:
[ ... ]
/**
* Returns:
* A pointer to a null-terminated string in O(1) time,
* (with regards to the length of the string and the required
* memory, if any) or `null` if * the time constraint
* can't be met.
*/
On 6/24/17 4:44 AM, Honey wrote:
Hi everyone!
Are there any guarantees about the values of padding bits in structs?
Thanks,
Honey
Any padding bits between fields should be 0 as long as the struct is
initialized (i.e. as long as you don't do Struct s = void).
Padding bits after the fields
On 6/24/17 1:18 AM, H. S. Teoh via Digitalmars-d-learn wrote:
On Fri, Jun 23, 2017 at 10:10:22PM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
On 06/23/2017 09:26 PM, Felix wrote:
That works, thanks!
I've just tried this, which seems cleaner:
import std.stdio;
import std.system;
import
I need a fast and hopefully relatively cross-platform (ELF, OMF,
COFF and MachO) way of checking if a slice points to data in the
read-only section of the binary, i.e. it's pointing to a
statically-allocated piece of memory.
Of course a simple solution using meta programming would be:
---
On 6/24/17 3:53 AM, Meta wrote:
The code:
alias Response = Nullable!(string, "empty response (error)");
Response processMessage(string commandModule)(string message, bool
isCommand)
{
import std.meta;
import std.string;
import std.traits;
import command_uda;
On Saturday, June 24, 2017 9:56:55 AM MDT Russel Winder via Digitalmars-d-
learn wrote:
> I note that:
>
> x.map!(…).array.sort
>
> is not valid, you have to have the parentheses on sort:
>
> x.map!(…).array.sort()
>
> Why?
Because the built-in sort for arrays has been deprecated but not yet
Russel Winder wrote:
On Sat, 2017-06-24 at 11:58 +0300, ketmar via Digitalmars-d-learn
wrote:
Russel Winder wrote:
I note that:
x.map!(…).array.sort
is not valid, you have to have the parentheses on sort:
x.map!(…).array.sort()
Why?
built-in property .sort kicks in and ruins
On Sat, 2017-06-24 at 11:58 +0300, ketmar via Digitalmars-d-learn
wrote:
> Russel Winder wrote:
>
> > I note that:
> >
> > x.map!(…).array.sort
> >
> > is not valid, you have to have the parentheses on sort:
> >
> > x.map!(…).array.sort()
> >
> > Why?
>
> built-in property .sort
Hi,
I'm trying to call std.algorithm.iteration.filter with a private
function as a predicate.
Here's a reduced example code:
// yo.d
import std.algorithm;
void moduleEntryPoint()
{
privateFunction1();
privateFunction2();
}
private:
void privateFunction1()
{
auto array = [0, 1, 2, 3,
Russel Winder wrote:
I note that:
x.map!(…).array.sort
is not valid, you have to have the parentheses on sort:
x.map!(…).array.sort()
Why?
built-in property .sort kicks in and ruins the day. luckily, it will be
completely removed in the upcoming major release.
I note that:
x.map!(…).array.sort
is not valid, you have to have the parentheses on sort:
x.map!(…).array.sort()
Why?
--
Russel.
=
Dr Russel Winder t: +44 20 7585 2200 voip:
Hi everyone!
Are there any guarantees about the values of padding bits in
structs?
Thanks,
Honey
ketmar wrote:
Meta wrote:
So I have no clue what I'm doing wrong. This is driving me insane.
h. known $#^#$@^@%.
enum SymName = ().stringof[2..$]; // this, instead of
symbol.stringof
dirty hack, let's hope that DMD devs won't change `.toString()` output
(i.e. first two chars will
Meta wrote:
So I have no clue what I'm doing wrong. This is driving me insane.
h. known $#^#$@^@%.
enum SymName = ().stringof[2..$]; // this, instead of
symbol.stringof
dirty hack, let's hope that DMD devs won't change `.toString()` output
(i.e. first two chars will always be
ketmar wrote:
`.toString()`
toChars().
;-)
The code:
alias Response = Nullable!(string, "empty response (error)");
Response processMessage(string commandModule)(string message,
bool isCommand)
{
import std.meta;
import std.string;
import std.traits;
import command_uda;
mixin("import " ~ commandModule ~ ';');
On 06/23/2017 10:18 PM, H. S. Teoh via Digitalmars-d-learn wrote:
On Fri, Jun 23, 2017 at 10:10:22PM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
On 06/23/2017 09:26 PM, Felix wrote:
That works, thanks!
I've just tried this, which seems cleaner:
import std.stdio;
import std.system;
42 matches
Mail list logo