Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 May 2013 21:47:17 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r250624 - in head/sys: amd64/amd64 i386/i386
Message-ID:  <201305132147.r4DLlHBr004251@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Mon May 13 21:47:17 2013
New Revision: 250624
URL: http://svnweb.freebsd.org/changeset/base/250624

Log:
  Improve readability of static assertions for OFFSET_* macros.
  
  Instead of doing all sorts of weird casting of constants to
  pointer-pointers, simply use the standard C offsetof() macro to obtain
  the offset of the respective fields in the structures.

Modified:
  head/sys/amd64/amd64/vm_machdep.c
  head/sys/i386/i386/vm_machdep.c

Modified: head/sys/amd64/amd64/vm_machdep.c
==============================================================================
--- head/sys/amd64/amd64/vm_machdep.c	Mon May 13 21:46:07 2013	(r250623)
+++ head/sys/amd64/amd64/vm_machdep.c	Mon May 13 21:47:17 2013	(r250624)
@@ -90,9 +90,10 @@ static u_int	cpu_reset_proxyid;
 static volatile u_int	cpu_reset_proxy_active;
 #endif
 
-CTASSERT((struct thread **)OFFSETOF_CURTHREAD ==
-    &((struct pcpu *)NULL)->pc_curthread);
-CTASSERT((struct pcb **)OFFSETOF_CURPCB == &((struct pcpu *)NULL)->pc_curpcb);
+_Static_assert(OFFSETOF_CURTHREAD == offsetof(struct pcpu, pc_curthread),
+    "OFFSETOF_CURTHREAD does not correspond with offset of pc_curthread.");
+_Static_assert(OFFSETOF_CURPCB == offsetof(struct pcpu, pc_curpcb),
+    "OFFSETOF_CURPCB does not correspond with offset of pc_curpcb.");
 
 struct savefpu *
 get_pcb_user_save_td(struct thread *td)

Modified: head/sys/i386/i386/vm_machdep.c
==============================================================================
--- head/sys/i386/i386/vm_machdep.c	Mon May 13 21:46:07 2013	(r250623)
+++ head/sys/i386/i386/vm_machdep.c	Mon May 13 21:47:17 2013	(r250624)
@@ -106,9 +106,10 @@ __FBSDID("$FreeBSD$");
 #define	NSFBUFS		(512 + maxusers * 16)
 #endif
 
-CTASSERT((struct thread **)OFFSETOF_CURTHREAD ==
-    &((struct pcpu *)NULL)->pc_curthread);
-CTASSERT((struct pcb **)OFFSETOF_CURPCB == &((struct pcpu *)NULL)->pc_curpcb);
+_Static_assert(OFFSETOF_CURTHREAD == offsetof(struct pcpu, pc_curthread),
+    "OFFSETOF_CURTHREAD does not correspond with offset of pc_curthread.");
+_Static_assert(OFFSETOF_CURPCB == offsetof(struct pcpu, pc_curpcb),
+    "OFFSETOF_CURPCB does not correspond with offset of pc_curpcb.");
 
 static void	cpu_reset_real(void);
 #ifdef SMP



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201305132147.r4DLlHBr004251>