Make the alignof() usage more portable in grep(1)

Remove NetBSD specific check and replace it with GCC extension __alignof__
that is available since GCC 2.x.

Requested by <kre>
This commit is contained in:
kamil 2018-06-14 10:14:39 +00:00
parent 24189a7035
commit 079a9ba6ba
1 changed files with 2 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: obstack.c,v 1.2 2018/06/13 17:32:29 kamil Exp $ */
/* $NetBSD: obstack.c,v 1.3 2018/06/14 10:14:39 kamil Exp $ */
/* obstack.c - subroutines used implicitly by object stack macros
Copyright (C) 1988-1994,96,97,98,99 Free Software Foundation, Inc.
@ -61,23 +61,7 @@
/* Determine default alignment. */
struct fooalign {char x; double d;};
#if defined(__NetBSD__)
#include <sys/param.h>
#endif
#ifndef __NetBSD_Prereq__
#define __NetBSD_Prereq__(a,b,c) 0
#endif
#if __NetBSD_Prereq__(8,0,0)
#include <stdalign.h>
// Avoid Undefined Behavior
#define DEFAULT_ALIGNMENT ((int)alignof(struct fooalign))
#else
#define DEFAULT_ALIGNMENT \
((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0))
#endif
#define DEFAULT_ALIGNMENT ((int)__alignof__(struct fooalign))
/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
But in fact it might be less smart and round addresses to as much as
DEFAULT_ROUNDING. So we prepare for it to do that. */