dlang.org icon indicating copy to clipboard operation
dlang.org copied to clipboard

add bitfields documentation

Open WalterBright opened this issue 2 years ago • 19 comments

Implementation: https://github.com/dlang/dmd/pull/13568

WalterBright avatar Jan 26 '22 04:01 WalterBright

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

dlang-bot avatar Jan 26 '22 04:01 dlang-bot

@CyberShadow can we please have a way to find what the errors are with DAutoTest?

WalterBright avatar Jan 26 '22 06:01 WalterBright

With DautoTest (unless you have LeTeX error in which case you're screwed) scroll all the way to the bottom of of the Build Log (click view).

In this case your problem is

Searching for tabs
./spec/struct.dd:134:	b.x = 4;

thewilsonator avatar Jan 26 '22 06:01 thewilsonator

Oh, I clicked on "base view". No errors there. I wonder what that is.

Anyhow, thanks! Hope it works now.

WalterBright avatar Jan 26 '22 06:01 WalterBright

The text mentions unit several times, but never says what it is.

MrSmith33 avatar Jan 26 '22 15:01 MrSmith33

@MrSmith33 it does now!

WalterBright avatar Jan 28 '22 00:01 WalterBright

The dmd bitfields PR has been merged, under the -preview=bitfields switch. This one needs to be, too.

WalterBright avatar May 10 '22 01:05 WalterBright

The dmd bitfields PR has been merged, under the -preview=bitfields switch. This one needs to be, too.

OK - As soon as it mentions the preview flag I will merge it

maxhaton avatar May 10 '22 01:05 maxhaton

does the best practices section at line 44 still hold?

Moth-Tolias avatar May 24 '22 16:05 Moth-Tolias

DeclaratorInitializer should also get a rule with BitfieldDeclarator in the grammar. DeclaratorIdentifier is only used for declarators after the first comma, while DeclaratorInitializer is used for the first declarator.

tim-dlang avatar May 28 '22 14:05 tim-dlang

Another potential ambiguity in the grammar:

void f()
{
    a: b;
}

The statement could be a bitfield with a as type and b as width, but it could also be a labeled statement with a as label and b as a statement. Bitfields are probably only allowed in classes and structs, but the grammar would also allow them in functions.

Edit: The text already says "Bit fields can only be fields in structs, unions and classes.", so that may be enough.

tim-dlang avatar May 28 '22 14:05 tim-dlang

@WalterBright you may want to update this part: https://github.com/dlang/dlang.org/blob/ae9d2d63077db4daff8407280d4e6ece1547e942/spec/struct.dd#L90-L94

AndrejMitrovic avatar Oct 17 '22 15:10 AndrejMitrovic

@maxhaton If bitfields are here to stay it would be good to merge this after adding any of the diff suggestions as you see fit. After that I can make a pull to fix https://github.com/dlang/dlang.org/pull/3190#issuecomment-1140274338

ntrel avatar Dec 03 '22 11:12 ntrel

We really shouldn't document this useless trash feature that never passed the DIP review to be added to the language.

adamdruppe avatar Dec 22 '22 13:12 adamdruppe

you may want to update this part

Done.

WalterBright avatar Nov 06 '23 06:11 WalterBright

Ready to merge.

WalterBright avatar Nov 06 '23 07:11 WalterBright

@dkorpel see https://github.com/dlang/dlang.org/pull/3190/files#diff-dee70e840ada3a820b3a373d649812b1157fd584ed0837e4a937ea3418f093e3R212

WalterBright avatar Nov 06 '23 19:11 WalterBright

A preview switch doesn't imply it's not part of the language, there are preview switches for current language features.

dkorpel avatar Nov 07 '23 10:11 dkorpel

Since bitfields do not influence anything else in the language semantics, there's no longer a purpose to putting bitfields behind a preview switch.

WalterBright avatar Jan 23 '24 03:01 WalterBright