summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/sizeof.c
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>2002-02-21 01:55:05 +0000
committerAndrew Cagney <cagney@redhat.com>2002-02-21 01:55:05 +0000
commitcb1f500170042bece8f120c6db0405675d5baf12 (patch)
tree897a528828ae0728eba988a263742de7154ca5fa /gdb/testsuite/gdb.base/sizeof.c
parentb699306586355624375f33481f894c8d46b0d664 (diff)
downloadgdb-cb1f500170042bece8f120c6db0405675d5baf12.tar.gz
* gdb.base/sizeof.c (main): Call fill_structs. Print value of
signed, unsigned and straight char. (padding_char, padding_short, padding_int, padding_long, padding_long_long, padding_float, padding_double, padding_long_double): New global variables. (fill, fill_structs): New functions. * gdb.base/sizeof.exp: Check for signed and unsigned char. Check for correctly sized writes. Update copyright. (get_valueof): New procedure. (get_sizeof): Call get_valueof. (check_valueof): New procedure. (check_padding): New procedure.
Diffstat (limited to 'gdb/testsuite/gdb.base/sizeof.c')
-rw-r--r--gdb/testsuite/gdb.base/sizeof.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/sizeof.c b/gdb/testsuite/gdb.base/sizeof.c
index 51f8c2f5e2a..95d379ee9ae 100644
--- a/gdb/testsuite/gdb.base/sizeof.c
+++ b/gdb/testsuite/gdb.base/sizeof.c
@@ -1,8 +1,105 @@
#include <stdio.h>
+typedef char padding[16];
+
+struct {
+ padding p1;
+ char v;
+ padding p2;
+} padding_char;
+
+struct {
+ padding p1;
+ short v;
+ padding p2;
+} padding_short;
+
+struct {
+ padding p1;
+ int v;
+ padding p2;
+} padding_int;
+
+struct {
+ padding p1;
+ long v;
+ padding p2;
+} padding_long;
+
+struct {
+ padding p1;
+ long long v;
+ padding p2;
+} padding_long_long;
+
+struct {
+ padding p1;
+ float v;
+ padding p2;
+} padding_float;
+
+struct {
+ padding p1;
+ double v;
+ padding p2;
+} padding_double;
+
+struct {
+ padding p1;
+ long double v;
+ padding p2;
+} padding_long_double;
+
+static void
+fill (void *buf, long sizeof_buf)
+{
+ char *p = buf;
+ int i;
+ for (i = 0; i < sizeof_buf; i++)
+ p[i] = "The quick brown dingo jumped over the layzy dog."[i];
+}
+
+void
+fill_structs (void)
+{
+ fill (&padding_char.p1, sizeof (padding));
+ fill (&padding_char.v, sizeof (padding_char.v));
+ fill (&padding_char.p2, sizeof (padding));
+
+ fill (&padding_short.p1, sizeof (padding));
+ fill (&padding_short.v, sizeof (padding_short.v));
+ fill (&padding_short.p2, sizeof (padding));
+
+ fill (&padding_int.p1, sizeof (padding));
+ fill (&padding_int.v, sizeof (padding_int.v));
+ fill (&padding_int.p2, sizeof (padding));
+
+ fill (&padding_long.p1, sizeof (padding));
+ fill (&padding_long.v, sizeof (padding_long.v));
+ fill (&padding_long.p2, sizeof (padding));
+
+ fill (&padding_long_long.p1, sizeof (padding));
+ fill (&padding_long_long.v, sizeof (padding_long_long.v));
+ fill (&padding_long_long.p2, sizeof (padding));
+
+ fill (&padding_float.p1, sizeof (padding));
+ fill (&padding_float.v, sizeof (padding_float.v));
+ fill (&padding_float.p2, sizeof (padding));
+
+ fill (&padding_double.p1, sizeof (padding));
+ fill (&padding_double.v, sizeof (padding_double.v));
+ fill (&padding_double.p2, sizeof (padding));
+
+ fill (&padding_long_double.p1, sizeof (padding));
+ fill (&padding_long_double.v, sizeof (padding_long_double.v));
+ fill (&padding_long_double.p2, sizeof (padding));
+}
+
int
main ()
{
+ fill_structs ();
+
printf ("sizeof (char) == %d\n", sizeof (char));
printf ("sizeof (short) == %d\n", sizeof (short));
printf ("sizeof (int) == %d\n", sizeof (int));
@@ -15,5 +112,11 @@ main ()
printf ("sizeof (float) == %d\n", sizeof (float));
printf ("sizeof (double) == %d\n", sizeof (double));
printf ("sizeof (long double) == %d\n", sizeof (long double));
+
+ /* Signed char? */
+ printf ("valueof ((int) (char) -1) == %d\n", (int) (char) -1);
+ printf ("valueof ((int) (signed char) -1) == %d\n", (int) (signed char) -1);
+ printf ("valueof ((int) (unsigned char) -1) == %d\n", (int) (unsigned char) -1);
+
return 0;
}