diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.misc-tests/sort2.c | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.misc-tests/sort2.c')
-rw-r--r-- | gcc/testsuite/gcc.misc-tests/sort2.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.misc-tests/sort2.c b/gcc/testsuite/gcc.misc-tests/sort2.c new file mode 100644 index 000000000..06b150b93 --- /dev/null +++ b/gcc/testsuite/gcc.misc-tests/sort2.c @@ -0,0 +1,54 @@ +/* Simple test program: bubble sort of a fixed table. */ +/* This demonstrates some of the compiler's common-subexpression*/ +/* elimination capabilities. For example, inspect the code */ +/* generated for procedure Sort_array. See the Programmer's */ +/* Guide for how to request an assembly listing on your host. */ + +typedef unsigned char boolean; + +void Sort_array(); +int Tab[100]; + +main () { + int I,J,K,L; + +for (L = 0; L < 1000; L++) { + /* Initialize the table that will be sorted. */ + K = 0; + for (I = 9; I >= 0; I--) + for (J = I*10; J < (I+1)*10; J++) + Tab[K++] = J&1 ? J+1 : J-1; + +/* Print_array(); */ + Sort_array(Tab,99); /* Sort it. */ +/* Print_array(); */ +} + return 0; +} + +void Sort_array(Tab,Last) int Tab[]; int Last; { + boolean Swap; + int Temp,I; + do { + Swap = 0; + for (I = 0; I<Last; I++) + if (Tab[I] > Tab[I+1]) { + Temp = Tab[I]; + Tab[I] = Tab[I+1]; + Tab[I+1] = Temp; + Swap = 1; + } + } + while (Swap); +} + + +void Print_array() { + int I,J; + /*printf("\nArray Contents:\n");*/ + for (I=0; I<=9; I++) { + /*printf("%5d:",10*I); */ + for (J=0; J<=9; J++); /*printf("%5d",Tab[10*I+J]); */ + /* printf("\n");*/ + } +} |