Skip to content

Commit

Permalink
Implementing offsetof
Browse files Browse the repository at this point in the history
  • Loading branch information
fedi-nabli committed Apr 6, 2024
1 parent 8c10788 commit 06e497f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions fd_includes/stddef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef STDDEF_H
#define STDDEF_H

#include "stddef-internal.h"

#define offsetof(TYPE, MEMBER) &((TYPE*)0x00)->MEMBER

#endif
File renamed without changes.
Empty file.
2 changes: 1 addition & 1 deletion preprocessor/static-includes/stddef.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

void preprocessor_stddef_internal_include(struct preprocessor* preprocessor, struct preprocessor_included_file* file)
{
#warning "Implement stddef"
// Do nothing
}
4 changes: 3 additions & 1 deletion test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stddef.h>

struct dog
{
int x;
Expand All @@ -6,5 +8,5 @@ struct dog

int main()
{
return &((struct dog*)0x00)->y;
return offsetof(struct dog, y);
}

0 comments on commit 06e497f

Please sign in to comment.