printf.c

00001 /*
00002  * Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
00003  * to the MC1322x project (http://mc1322x.devl.org)
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. Neither the name of the Institute nor the names of its contributors
00015  *    may be used to endorse or promote products derived from this software
00016  *    without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00022  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00024  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00025  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00026  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00027  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * This file is part of libmc1322x: see http://mc1322x.devl.org
00031  * for details. 
00032  *
00033  *
00034  */
00035 
00036 #include <mc1322x.h>
00037 #include <board.h>
00038 
00039 #include <stdio.h>
00040 #include <math.h>
00041 
00042 #include "tests.h"
00043 #include "config.h"
00044 
00045 #define print_size(x) do { \
00046         printf("sizeof(");                      \
00047         printf(#x);                             \
00048         printf("): %d\n", sizeof(x));           \
00049         } while(0)
00050 
00051 #if (__linux__)
00052 FILE *stderr;
00053 
00054 void __assert_fail(void) {
00055         return;
00056 }
00057         
00058 int fputs(const char *s, FILE *stream) {
00059         return 0;
00060 }
00061 
00062 size_t fwrite(const void *ptr, size_t size, size_t nmemb,
00063               FILE *stream) {
00064         return 0;
00065 }
00066 #endif
00067 
00068 int main(void)
00069 {
00070         char *ptr = "Hello world!";
00071         char *np = 0;
00072         int i = 5;
00073         unsigned int bs = sizeof(int)*8;
00074         int mi;
00075 //      char buf[80];
00076 
00077         uart_init(INC, MOD, SAMP);
00078 
00079         print_size(int8_t);
00080         print_size(uint8_t);
00081         print_size(int16_t);
00082         print_size(uint16_t);
00083         print_size(int32_t);
00084         print_size(uint32_t);
00085         print_size(int64_t);
00086         print_size(uint64_t);
00087 
00088         mi = (1 << (bs-1)) + 1;
00089         printf("%s\n", ptr);
00090         printf("printf test\n");
00091         printf("%s is null pointer\n", np);
00092         printf("%d = 5\n", i);
00093         printf("%d = - max int\n", mi);
00094         printf("char %c = 'a'\n", 'a');
00095         printf("hex %x = ff\n", 0xff);
00096         printf("hex %02x = 00\n", 0);
00097         printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3);
00098         printf("%d %s(s)", 0, "message");
00099         printf("\n");
00100         printf("%d %s(s) with %%\n", 0, "message");
00101 
00102         printf("sqrt(5) * 100  = %d\n", (int) (sqrt(5)*100));
00103 
00104 //      sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
00105 //      sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
00106 //      sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);
00107 //      sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);
00108 //      sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);
00109 //      sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);
00110 //      sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);
00111 //      sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);
00112 
00113         while(1) { continue; }
00114 }
00115 
00116 /*
00117  * this should display (on 32bit int machine) :
00118  *
00119  * Hello world!
00120  * printf test
00121  * (null) is null pointer
00122  * 5 = 5
00123  * -2147483647 = - max int
00124  * char a = 'a'
00125  * hex ff = ff
00126  * hex 00 = 00
00127  * signed -3 = unsigned 4294967293 = hex fffffffd
00128  * 0 message(s)
00129  * 0 message(s) with %
00130  * justif: "left      "
00131  * justif: "     right"
00132  *  3: 0003 zero padded
00133  *  3: 3    left justif.
00134  *  3:    3 right justif.
00135  * -3: -003 zero padded
00136  * -3: -3   left justif.
00137  * -3:   -3 right justif.
00138  */

Generated on Mon Apr 11 14:23:38 2011 for Contiki 2.5 by  doxygen 1.6.1