Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Compile time byte swapping for HTONS, HTONL, NTOHS, NTOHL etc. #3812

Closed
DipSwitch opened this issue Sep 10, 2015 · 7 comments
Closed
Assignees
Labels
State: stale State: The issue / PR has no activity for >185 days Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Comments

@DipSwitch
Copy link
Member

This would be useful so you can create enums like:

# define CT_HTONS(x)    (((x >> 8) & 0x00FF) | ((x << 8) & 0xFF00))
# define CT_HTONL(x)    (((x >> 24) & 0x000000FF) | ((x >> 8) & 0x0000FF00) | ((x << 8) & 0x00FF0000) | ((x << 24) & 0xFF000000))

typedef enum {
    A                       = CT_HTONS(0x0001),
    AAAA                    = CT_HTONS(0x001C),
} dns_query_type;

We already use this our self in some projects.

@DipSwitch DipSwitch changed the title core: Compile time macro byte swapping for HTONS, HTONL, NTOHS, NTOHL etc. core: Compile time byte swapping for HTONS, HTONL, NTOHS, NTOHL etc. Sep 10, 2015
@jnohlgard
Copy link
Member

jnohlgard commented Sep 10, 2015 via email

@DipSwitch
Copy link
Member Author

Only static inline functions, these the compiler can't optimize when defining enum's.

@DipSwitch DipSwitch added the Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation label Dec 27, 2015
@miri64 miri64 added this to the Release 2016.03 milestone Feb 9, 2016
@jnohlgard
Copy link
Member

Good idea.
@DipSwitch do you want to provide a PR?

@haukepetersen
Copy link
Contributor

postponed to 2016.07

@haukepetersen haukepetersen modified the milestones: Release 2016.07, Release 2016.04 Mar 31, 2016
@kYc0o
Copy link
Contributor

kYc0o commented Jul 25, 2016

Postponed again to 2010.10

@kYc0o kYc0o modified the milestones: Release 2016.10, Release 2016.07 Jul 25, 2016
@miri64 miri64 modified the milestones: Release 2017.01, Release 2016.10 Oct 31, 2016
@PeterKietzmann
Copy link
Member

How about #5453

@PeterKietzmann PeterKietzmann modified the milestones: Release 2017.01, Release 2017.04 Jan 26, 2017
@aabadie aabadie modified the milestone: Release 2017.10 Jul 14, 2017
@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this as completed Sep 10, 2019
basilfx added a commit to basilfx/RIOT that referenced this issue Jul 26, 2023
To convert the supplied argument `htons` and friends will use a
simple formula instead of a function call, iff the value of the
argument is known at compile time.

This enables the use in enum definitions such as:

```c
typedef enum {
    A                       = htons(0x0001),
    AAAA                    = htons(0x001C),
} dns_query_type;
```

Fixes RIOT-OS#3812
basilfx added a commit to basilfx/RIOT that referenced this issue Jul 26, 2023
To convert the supplied argument `htons` and friends will use a
simple formula instead of a function call, iff the value of the
argument is known at compile time.

This enables the use in enum definitions such as:

```c
typedef enum {
    A                       = htons(0x0001),
    AAAA                    = htons(0x001C),
} dns_query_type;
```

Fixes RIOT-OS#3812
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
State: stale State: The issue / PR has no activity for >185 days Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

No branches or pull requests

7 participants