Skip to content

Commit 7ed2880

Browse files
committed
Remove explicit padding from struct definitions
Modern compilers align structs appropriately according to the alignment requirements of the member types. Removing the padding reduces the size of many of the structs, and the alignment remains the same.
1 parent 4910b9a commit 7ed2880

File tree

7 files changed

+4
-268
lines changed

7 files changed

+4
-268
lines changed

sources/extcmd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ typedef struct ExternalChannel {
280280
int fsend; /*stdin of the external process*/
281281
int killSignal; /*signal to kill*/
282282
int daemonize;/*0 --neither setsid nor daemonize, !=0 -- full daemonization*/
283-
PADPOINTER(0,3,0,0);
284283
} EXTHANDLE;
285284

286285

sources/form3.h

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ typedef ULONG RLONG; /* Used in reken.c. */
235235
typedef int64_t MLONG; /* See commentary in minos.h. */
236236
/*
237237
* NOTE: we don't use the standard _Bool (or C++ bool) because its size is
238-
* implementation-dependent and messes up the traditional PADXXX macros.
238+
* implementation-dependent.
239239
*/
240240
typedef char BOOL;
241241
/* E.g. in 32-bits */
@@ -279,79 +279,6 @@ template<typename T> struct calc {
279279
#endif
280280
#endif
281281

282-
/*
283-
* Macros to be inserted at the end of a structure to align the whole structure.
284-
*
285-
* In the currently available systems,
286-
* sizeof(POSITION) >= sizeof(pointers) == sizeof(LONG) >= sizeof(int)
287-
* >= sizeof(WORD) >= sizeof(UBYTE) = 1.
288-
* (POSITION is defined in struct.h and contains only an off_t variable.)
289-
* Thus, if we put members of a structure in this order and use those macros,
290-
* then we can align the data without relying on extra paddings added by
291-
* the compiler. For example,
292-
* typedef struct {
293-
* int *a;
294-
* LONG b;
295-
* WORD c[2];
296-
* UBYTE d;
297-
* PADPOINTER(1,0,2,1);
298-
* } A;
299-
* typedef struct {
300-
* POSITION p;
301-
* A a; // aligned same as pointers
302-
* int *b;
303-
* LONG c;
304-
* UBYTE d;
305-
* PADPOSITION(1,1,0,0,1+sizeof(A));
306-
* } B;
307-
* The cost for the use of those PADXXX macros is a padding (>= 1 byte) will
308-
* be always inserted even in the case that no padding is actually needed.
309-
*
310-
* Numbers for the arguments have to be calculated manually and so very
311-
* error-prone. Be careful!
312-
*
313-
* Note that there is a 32-bit system in which off_t is aligned on 8-byte
314-
* boundary, (e.g., Cygwin with large file support), but still the above
315-
* inequalities are satisfied.
316-
*
317-
* The legendary story of these macros--they fixed some problems in ancient
318-
* times when compilers were unreliable and didn't know how to correctly compute
319-
* structure paddings--has been handed down, though nowadays there are only
320-
* disadvantages for them in practice (ancient compilers most likely can't
321-
* compile C99 and C++98+TR1 sources anyway).
322-
*/
323-
#define PADDUMMY(type, size) \
324-
UBYTE d_u_m_m_y[form_alignof(type) - ((size) & (form_alignof(type) - 1))]
325-
#define PADPOSITION(ptr_,long_,int_,word_,byte_) \
326-
PADDUMMY(off_t, \
327-
+ sizeof(int *) * (ptr_) \
328-
+ sizeof(LONG) * (long_) \
329-
+ sizeof(int) * (int_) \
330-
+ sizeof(WORD) * (word_) \
331-
+ sizeof(UBYTE) * (byte_) \
332-
)
333-
#define PADPOINTER(long_,int_,word_,byte_) \
334-
PADDUMMY(int *, \
335-
+ sizeof(LONG) * (long_) \
336-
+ sizeof(int) * (int_) \
337-
+ sizeof(WORD) * (word_) \
338-
+ sizeof(UBYTE) * (byte_) \
339-
)
340-
#define PADLONG(int_,word_,byte_) \
341-
PADDUMMY(LONG, \
342-
+ sizeof(int) * (int_) \
343-
+ sizeof(WORD) * (word_) \
344-
+ sizeof(UBYTE) * (byte_) \
345-
)
346-
#define PADINT(word_,byte_) \
347-
PADDUMMY(int, \
348-
+ sizeof(WORD) * (word_) \
349-
+ sizeof(UBYTE) * (byte_) \
350-
)
351-
#define PADWORD(byte_) \
352-
PADDUMMY(WORD, \
353-
+ sizeof(UBYTE) * (byte_) \
354-
)
355282

356283
/*
357284
#define WITHPCOUNTER

sources/optimize.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class tree_node {
129129
int num_visits;
130130
WORD var;
131131
bool finished;
132-
PADPOINTER(1,1,1,1);
133132

134133
tree_node (int _var=0):
135134
sum_results(0), num_visits(0), var(_var), finished(false) {}

sources/parallel.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,6 @@ typedef struct {
24802480
VectorStruct(WORD) buf;
24812481
LONG size;
24822482
WORD type;
2483-
PADPOINTER(1,0,1,0);
24842483
} dollar_buf;
24852484

24862485
/* Buffers used to store data for each variable from each slave. */

sources/parallel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ typedef struct {
158158
int *from;
159159
int numbufs; /* number of cyclic buffers */
160160
int active; /* flag telling which buffer is active */
161-
PADPOINTER(0,2,0,0);
162161
} PF_BUFFER;
163162

164163
/*
@@ -182,7 +181,6 @@ typedef struct ParallelVars {
182181
int log; /* flag for logging mode */
183182
WORD numsbufs; /* number of cyclic send buffers (PF.sbuf->numbufs) */
184183
WORD numrbufs; /* number of cyclic receive buffers (PF.rbufs[i]->numbufs, i=1,...numtasks-1) */
185-
PADPOSITION(2,0,8,2,0);
186184
} PARALLELVARS;
187185

188186
extern PARALLELVARS PF;

sources/poly.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ class poly {
171171

172172
static void push_heap (PHEAD WORD **, int);
173173
static void pop_heap (PHEAD WORD **, int);
174-
175-
PADPOINTER(1,0,2,0);
176174
};
177175

178176
// comparison class for monomials (for std::sort)

0 commit comments

Comments
 (0)