xpcom/tests/ShowAlignments.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/tests/ShowAlignments.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,38 @@
     1.4 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* show the size and alignment requirements of various types */
    1.10 +
    1.11 +#include "nsMemory.h"
    1.12 +#include <stdio.h>
    1.13 +
    1.14 +struct S {
    1.15 +  double d;
    1.16 +  char c;
    1.17 +  short s;
    1.18 +};
    1.19 +
    1.20 +int main()
    1.21 +{
    1.22 +  static const char str[] =
    1.23 +    "Type %s has size %u and alignment requirement %u\n";
    1.24 +  #define SHOW_TYPE(t_) \
    1.25 +    printf(str, #t_, unsigned(sizeof(t_)), unsigned(NS_ALIGNMENT_OF(t_)))
    1.26 +
    1.27 +  SHOW_TYPE(char);
    1.28 +  SHOW_TYPE(unsigned short);
    1.29 +  SHOW_TYPE(int);
    1.30 +  SHOW_TYPE(long);
    1.31 +  SHOW_TYPE(uint8_t);
    1.32 +  SHOW_TYPE(int16_t);
    1.33 +  SHOW_TYPE(uint32_t);
    1.34 +  SHOW_TYPE(void*);
    1.35 +  SHOW_TYPE(double);
    1.36 +  SHOW_TYPE(short[7]);
    1.37 +  SHOW_TYPE(S);
    1.38 +  SHOW_TYPE(double S::*);
    1.39 +
    1.40 +  return 0;
    1.41 +}

mercurial