int main() { int intVariable = 10; float floatVariable = 2.5f; int* intPointer = &intVariable; int intValue = *intPointer; short shortVariable = 10; long longVariable = 65535; double doubleVariable = 0.000125f; printf("int:"); show_int(intVariable); printf("float:"); show_float(floatVariable); printf("pointer:"); show_pointer(intPointer); printf("short:"); show_short(shortVariable); printf("long:"); show_long(longVariable); printf("double:"); show_double(doubleVariable); }
void run_255() { printf("\nexersize 2.55: \n"); show_int(1); show_short(12345); show_int(12345); show_long(12345); show_double(12345); }
static void test() { short s = 0x34AB; long l = 0x1122AABB; double d = 1.0; show_short(s); show_long(l); show_double(d); }
int main (void) { short short_x = 12345; long long_x = 12345; double double_x = 12345.0; printf ("show_short:\n"); show_short (short_x); printf ("show_long:\n"); show_long (long_x); printf ("show_double:\n"); show_double (double_x); }
int main() { int a = 10; float b = 11.5; double c = 13.33; void *d = &a; show_int(a); printf("\n"); show_float(b); printf("\n"); show_double(c); printf("\n"); show_pointer(d); getchar(); }
int main() { if(is_big_endian()) printf("\nbig endian"); else printf("\nlittle endian"); show_char('C'); show_int(-535703600); show_double(1.7E+308); printf("\n"); return EXIT_SUCCESS; }
void test_show_bytes(int val) { int ival = val; float fval = (float) ival; int *pval = &ival; short sval = (short) ival; long lval = (long) ival; double dval = (double) ival; show_int(ival); show_float(fval); show_pointer(pval); show_short(sval); show_long(lval); show_double(dval); printf("\n"); }
static int xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char *msg_fmt) { char *p = ev->buffer; int rem_size = ev->buffer_size; int precision = -1; int length = -1; char *q; for (q = l->data ; *q != '\0' ; q++) { if (*q == '%') { q++; handle_modifier: switch (*q) { case '\0': fprintf(stderr, "Layout format (%s) ending with %%\n", (char *)l->data); xbt_abort(); case '%': *p = '%'; check_overflow(1); break; case 'n': /* platform-dependant line separator; LOG4J compliant */ *p = '\n'; check_overflow(1); break; case 'e': /* plain space; SimGrid extension */ *p = ' '; check_overflow(1); break; case '.': /* precision specifier */ precision = strtol(q + 1, &q, 10); goto handle_modifier; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* length modifier */ length = strtol(q, &q, 10); goto handle_modifier; case 'c': /* category name; LOG4J compliant should accept a precision postfix to show the hierarchy */ show_string(ev->cat->name); break; case 'p': /* priority name; LOG4J compliant */ show_string(xbt_log_priority_names[ev->priority]); break; case 'h': /* host name; SimGrid extension */ show_string(SIMIX_host_self_get_name()); break; case 't': /* thread name; LOG4J compliant */ show_string(SIMIX_process_self_get_name()); break; case 'P': /* process name; SimGrid extension */ show_string(xbt_procname()); break; case 'i': /* process PID name; SimGrid extension */ show_int(xbt_getpid()); break; case 'F': /* file name; LOG4J compliant */ show_string(ev->fileName); break; case 'l': { /* location; LOG4J compliant */ int len, sz; set_sz_from_precision(); len = snprintf(p, sz, "%s:%d", ev->fileName, ev->lineNum); check_overflow(MIN(sz, len)); break; } case 'L': /* line number; LOG4J compliant */ show_int(ev->lineNum); break; case 'M': /* method (ie, function) name; LOG4J compliant */ show_string(ev->functionName); break; case 'b': /* backtrace; called %throwable in LOG4J */ case 'B': /* short backtrace; called %throwable{short} in LOG4J */ // TODO, backtrace #if 0 && HAVE_BACKTRACE && HAVE_EXECINFO_H && HAVE_POPEN && defined(ADDR2LINE) { xbt_ex_t e(""); e.used = backtrace((void **) e.bt, XBT_BACKTRACE_SIZE); e.bt_strings = NULL; xbt_ex_setup_backtrace(&e); if (*q == 'B') { show_string(e.bt_strings[1] + 8); } else { xbt_strbuff_t buff = xbt_strbuff_new(); int i; xbt_strbuff_append(buff, e.bt_strings[1] + 8); for (i = 2; i < e.used; i++) { xbt_strbuff_append(buff, "\n"); xbt_strbuff_append(buff, e.bt_strings[i] + 8); } show_string(buff->data); xbt_strbuff_free(buff); } } #else show_string("(no backtrace on this arch)"); #endif break; case 'd': /* date; LOG4J compliant */ show_double(surf_get_clock()); break; case 'r': /* application age; LOG4J compliant */ show_double(surf_get_clock() - format_begin_of_time); break; case 'm': { /* user-provided message; LOG4J compliant */ int len, sz; set_sz_from_precision(); len = vsnprintf(p, sz, msg_fmt, ev->ap); check_overflow(MIN(sz, len)); break; } default: fprintf(stderr, ERRMSG, *q, (char *)l->data); xbt_abort(); } } else { *p = *q; check_overflow(1); } } *p = '\0'; return 1; }
static void xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char *msg_fmt, xbt_log_appender_t app) { char *p, *q; char tmpfmt[50]; int precision = -1; int length = -1; p = ev->buffer; q = l->data; while (*q != '\0') { if (*q == '%') { q++; handle_modifier: switch (*q) { case '\0': fprintf(stderr, "Layout format (%s) ending with %%\n", (char *) l->data); abort(); case '%': *p++ = '%'; break; case 'n': /* platform-dependant line separator (LOG4J compliant) */ p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "\n"); check_overflow; break; case 'e': /* plain space (SimGrid extension) */ p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), " "); check_overflow; break; case '.': /* precision specifyier */ q++; sscanf(q, "%d", &precision); q += (precision>9?2:1); goto handle_modifier; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* length modifier */ sscanf(q, "%d", &length); q += (length>9?2:1); goto handle_modifier; case 'c': /* category name; LOG4J compliant should accept a precision postfix to show the hierarchy */ show_string(ev->cat->name); break; case 'p': /* priority name; LOG4J compliant */ show_string(xbt_log_priority_names[ev->priority]); break; case 'h': /* host name; SimGrid extension */ show_string(gras_os_myname()); break; case 't': /* thread name; LOG4J compliant */ show_string(xbt_thread_self_name()); break; case 'P': /* process name; SimGrid extension */ show_string(xbt_procname()); break; case 'i': /* process PID name; SimGrid extension */ show_int((*xbt_getpid) ()); break; case 'F': /* file name; LOG4J compliant */ show_string(ev->fileName); break; case 'l': /* location; LOG4J compliant */ if (precision == -1) { p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d", ev->fileName, ev->lineNum); check_overflow; } else { p += snprintf(p, (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), precision), "%s:%d", ev->fileName, ev->lineNum); check_overflow; precision = -1; } break; case 'L': /* line number; LOG4J compliant */ show_int(ev->lineNum); break; case 'M': /* method (ie, function) name; LOG4J compliant */ show_string(ev->functionName); break; case 'b': /* backtrace; called %throwable in LOG4J */ case 'B': /* short backtrace; called %throwable{short} in LOG4J */ #if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) { xbt_ex_t e; int i; e.used = backtrace((void **) e.bt, XBT_BACKTRACE_SIZE); e.bt_strings = NULL; e.msg = NULL; e.remote = 0; xbt_backtrace_current(&e); if (*q == 'B') { show_string(e.bt_strings[2] + 8); } else { for (i = 2; i < e.used; i++) if (precision == -1) { p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s\n", e.bt_strings[i] + 8); check_overflow; } else { p += sprintf(p, "%.*s\n", (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), precision), e.bt_strings[i] + 8); check_overflow; precision = -1; } } xbt_ex_free(e); } #else p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "(no backtrace on this arch)"); check_overflow; #endif break; case 'd': /* date; LOG4J compliant */ show_double(gras_os_time()); break; case 'r': /* application age; LOG4J compliant */ show_double(gras_os_time() - format_begin_of_time); break; case 'm': /* user-provided message; LOG4J compliant */ if (precision == -1) { p += vsnprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), msg_fmt, ev->ap); check_overflow; } else { p += vsnprintf(p, (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), precision), msg_fmt, ev->ap); check_overflow; precision = -1; } break; default: fprintf(stderr, ERRMSG, *q, (char *) l->data); abort(); } q++; } else { *(p++) = *(q++); check_overflow; } } *p = '\0'; app->do_append(app, ev->buffer); }