libc

How to sleep for a few microseconds

守給你的承諾、 提交于 2019-11-30 09:40:42
Consider the following code: #include <stdio.h> #include <time.h> #include <math.h> // Compile with gcc -lrt -lm -o test_clock test_clock.c #define CLOCK CLOCK_MONOTONIC int main(int argc, char** argv) { double temp, elapsed; int j; struct timespec requestStart, requestEnd, req; // Pseudo-sleep clock_gettime(CLOCK, &requestStart); temp = 0; for(j=0; j < 40; j++) temp += sin(j); clock_gettime(CLOCK, &requestEnd); elapsed = ( requestEnd.tv_sec - requestStart.tv_sec ) / 1e-6 + ( requestEnd.tv_nsec - requestStart.tv_nsec ) / 1e3; printf("Elapsed: %lf us\n", elapsed); // Nanosleep clock_gettime

How to write my own printf() in C?

早过忘川 提交于 2019-11-30 06:38:16
问题 Actually I am trying to write my own printf() in C by using varags. But I am not getting the correct solution for this. Can anyone help me out? 回答1: Before implementation of printf( ) function we have to deal with unusual problem which is variable arguments. As we know that printf can take many arguments besides string. So we have to use a standard library called stdarg.h to handle this variable argument problem. In this implementation context, we don’t need learn whole stdarg.h library

App randomly crashes with A/libc: fatal signal 11

亡梦爱人 提交于 2019-11-30 05:32:29
问题 so my app started randomly crashing with Fatal Signal 11 (on random activities, some seem to do it more often than other but I haven't found a pattern yet). I have no idea why, it didn't do it before and my code didn't change that much and mainly, the same code works fine for my colleague. what I tired to do to fix it: Rebooting my machine Triple checking everything in my code running gradlew clean and rebuilding everything Checking out an older version from VCS (that I'm sure worked)

Why don't I get a link error when I provide my own malloc and free?

混江龙づ霸主 提交于 2019-11-30 03:09:33
问题 I'm trying to implement a simple fit first memory management algorithm. So I've got a C file with my own void* malloc(size_t) and void free(void*) When generating a .out file with gcc, I'm expecting a link error because it'll conflict with the existing standard implementation. But my file links fine. Please help me to understand. 回答1: I'm expecting a link error because it'll conflict with the existing standard implementation. Your expectation is incorrect: most UNIX libc implementations

Android Static Linking vs Dynamic Linking against glibc

只谈情不闲聊 提交于 2019-11-30 02:51:01
问题 I have been cross-compiling some Linux tools (and some of my own C code) to Android and one of the challenges that I face is that Android's libc has some missing/stripped components and I end up patching my code to make it work with Android's libc (for e.g. a problem like this http://credentiality2.blogspot.com/2010/08/compile-ncurses-for-android.html) Q1 : How do I go about statically linking against glibc (and other dependencies) while cross-compiling with the arm toolchain (or ndk-build)?

Android libc.so crash?

只愿长相守 提交于 2019-11-30 02:30:39
I'm using AndEngine with the PhysicsBox2DExtension to make a game. My game keeps crashing and I get this in the unfiltered LogCat: 07-06 13:25:27.266: I/DEBUG(19582): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 07-06 13:25:27.266: I/DEBUG(19582): Build fingerprint: 'TMOUS/SGH-T959V/SGH-T959V/SGH-T959V:2.2.1/FROYO/VUVKD1:user/release-keys' 07-06 13:25:27.274: I/DEBUG(19582): pid: 22238, tid: 22263 >>> com.prattia.webs.testgfx5 <<< 07-06 13:25:27.274: I/DEBUG(19582): signal 11 (SIGSEGV), fault addr deadbaad 07-06 13:25:27.286: I/DEBUG(19582): r0 00000000 r1 afd14921 r2

Small libc for embedded systems

血红的双手。 提交于 2019-11-30 01:35:30
I am looking for a small libc for embedded use with freertos on a ARM7 microcontroller. I have looked at newlib, but it is a bit too complex for my needs. Newlib calls malloc() in a number of functions (e.g. printf()), which is not good for small embedded realtime systems. Does anyone know of a small, portable, open source libc implementation that will fit my application? Christoph PDCLib might fit your needs. It's still incomplete [broken link] , though, and probably in need of a lot more real-world testing. Its author goes by DevSolar here on SO. update 2012-11-01: As of 2012-08-14,

How did malloc and calloc end up with different signatures? [duplicate]

眉间皱痕 提交于 2019-11-30 00:37:51
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why calloc takes two arguments while malloc only one? There are lots of resources describing the difference in functionality between malloc and calloc , but I can't easily find one that describes the history behind the differing function signatures: void *calloc(size_t nmemb, size_t size); void *malloc(size_t size); Of course, the size in the former is the size for each member. Maybe the idea was that multiple

Is MSVCRT under Windows like glibc (libc) under *nix?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 00:11:55
I frequently come across Windows programs that bundle in MSVCRT (or their more current equivalents) with the program executables. On a typical PC, I would find many copies of the same .DLL's. My understanding is that MSVCRT is the C runtime library, somewhat analogous to glibc/libc.so under *nix. Why do Windows programs have to bring along their C libraries with them, instead of just sharing the system-wide libc? Update: thanks to Shog9, I started to read about SxS, which has further opened up my eyes to the DLL linkage issues (DLL Hell) - http://blogs.msdn.com/b/martynl/archive/2005/10/13

Where is stdarg.h?

陌路散爱 提交于 2019-11-29 18:24:20
问题 On my system (Mac OS 10.6) /usr/include/stdarg.h is: /* This file is public domain. */ /* GCC uses its own copy of this header */ #if defined(__GNUC__) #include_next <stdarg.h> #elif defined(__MWERKS__) #include "mw_stdarg.h" #else #error "This header only supports __MWERKS__." #endif So, if GCC uses its own copy of stdarg.h , where is it? I have no idea on what that #include_next means (maybe a GCC extension?), nor something about "MWERKS" (a compiler?). 回答1: <stdarg.h> , even more than most