Re: Is sizeof() available in D language?

2023-09-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 4, 2023 2:34:08 PM MDT Olivier Pisano via Digitalmars-d-
learn wrote:
> On Monday, 4 September 2023 at 09:41:54 UTC, BoQsc wrote:
> > I've seen everyone using **datatype**`.sizeof` property.
> >
> > https://dlang.org/spec/property.html#sizeof
> >
> > It's great, but I wonder if it differ in any way from the
> > standard C function `sizeof()`.
>
> Technically speaking, in C, sizeof is not a function, it is an
> operator. This is why it is not available in D (replaced by the
> .sizeof property).
>
> > https://www.geeksforgeeks.org/sizeof-operator-c/
> > https://en.cppreference.com/w/cpp/language/sizeof
> >
> > I'm seeking for some speed/performance, so that's why the
> > question.
> > Overall I'm alright with continuing using it.
>
> There is absolutely no difference in terms of runtime
> performance. In both cases, the compiler replaces it by the size
> of the type at compile-time.

Yeah. You can pretty much just think of C's sizeof and D's sizeof as being
the same thing with different syntaxes. In both cases, it's a compile-time
value that gives the size of a type in bytes. In neither case does how it is
calculated have any impact on the performance of the program.

- Jonathan M Davis





Re: Is sizeof() available in D language?

2023-09-04 Thread Olivier Pisano via Digitalmars-d-learn

On Monday, 4 September 2023 at 09:41:54 UTC, BoQsc wrote:

I've seen everyone using **datatype**`.sizeof` property.

https://dlang.org/spec/property.html#sizeof

It's great, but I wonder if it differ in any way from the 
standard C function `sizeof()`.



Technically speaking, in C, sizeof is not a function, it is an 
operator. This is why it is not available in D (replaced by the 
.sizeof property).




https://www.geeksforgeeks.org/sizeof-operator-c/
https://en.cppreference.com/w/cpp/language/sizeof

I'm seeking for some speed/performance, so that's why the 
question.

Overall I'm alright with continuing using it.


There is absolutely no difference in terms of runtime 
performance. In both cases, the compiler replaces it by the size 
of the type at compile-time.


Re: Is sizeof() available in D language?

2023-09-04 Thread user1234 via Digitalmars-d-learn

On Monday, 4 September 2023 at 09:41:54 UTC, BoQsc wrote:

I've seen everyone using **datatype**`.sizeof` property.

https://dlang.org/spec/property.html#sizeof

It's great, but I wonder if it differ in any way from the 
standard C function `sizeof()`.


https://www.geeksforgeeks.org/sizeof-operator-c/
https://en.cppreference.com/w/cpp/language/sizeof

I'm seeking for some speed/performance, so that's why the 
question.

Overall I'm alright with continuing using it.


In both case it's replaced at compile-time by an 
IntegerExpression (the ast node for an integer literal)


I would not loose too much time comparing the "postfix" style (D) 
with the "intrinsic" style (C). Possibly there might a few micro 
ops difference... so only significant compile-time difference for 
1 Billion `sizeof` ;)


Is sizeof() available in D language?

2023-09-04 Thread BoQsc via Digitalmars-d-learn

I've seen everyone using **datatype**`.sizeof` property.

https://dlang.org/spec/property.html#sizeof

It's great, but I wonder if it differ in any way from the 
standard C function `sizeof()`.


https://www.geeksforgeeks.org/sizeof-operator-c/
https://en.cppreference.com/w/cpp/language/sizeof

I'm seeking for some speed/performance, so that's why the 
question.

Overall I'm alright with continuing using it.