I’m looking to do some very basic micro benchmarking of small code paths, such as tight loops, that I’ve written in C++. I’m running on Linux and OSX, and using GCC. What facilities are there for sub millisecond accuracy? I am thinking a simple test of running the code path many times (sever…
Tag: c++
what is the ‘what’ command on AIX under LINUX
I am used to use what to find out some version string in my program, which is normal defined as a string in the c++ code, starting with “@(#)”. Now I cannot find it in Linux. Can anyone tell me what I am supposed to do? Thanks a lot! Answer The what command is part of the Source Code Control
C system function causes error ‘sh: Syntax error: “(” unexpected ‘
I wrote a simple program in C on Linux to delete all the files in a directory except one called svn like this: But when I compile and run it, the terminal says: sh: Syntax error: “(” unexpected However, when I type and run the command in the terminal directly, all things are done correctly. Any id…
Linux kernel module compiling
I try to compile simple linux kernel module: My makefile: Now i haven’t errors in my .c file. But when i try make in terminal: make: Nothing to be done for `all’. What’s wrong? Thank you. Answer The default command in your makefile is That instructs make to cd to /lib/modules/$(KVERSION)/bui…
Can I squeeze my own program between the preprocessor and compiler?
Is this a stupid question, or can I specify g++ to use a program between the preprocessor and compiler? Alternatively, I know that I can just run the preprocessor on a file (hence all the files). Then I am guessing there is a switch to run only the compiler. So I can manually invoke these two and put my progr…
How does a C compiler find that -lm is pointing to the file libm.a?
What’s .a files in C programming in linux ? Is it library file ? Here how compiler find that -lm is pointing to the file libm.a , and -lsocket as libsocket.a ? And if we add the header file to the program, Is it must we want to mention library while compiling ? Answer As Ignacio says, .a files are
How to obtain total available disk space in Posix systems?
I’m writing a cross-platform application, and I need the total available disk space. For posix systems (Linux and Macos) I’m using statvfs. I created this C++ method: Unfortunately I’m getting quite strange values I can’t understand. For instance: f_blocks = 73242188 f_bsize = 1048576 …
How to view symbols in object files?
How can I view symbols in a .o file? nm does not work for me. I use g++/linux. Answer Instead of nm, you can use the powerful objdump. See the man page for details. Try objdump -t myfile or objdump -T myfile. With the -C flag you can also demangle C++ names, like nm does.
System Time change detection on linux
I was reading about the licensing of software and one question that came to my mind is that “how software detect the change in system time and block themselves if someone changes system time?”. Since there is no other reference available(provided we don’t have internet connection, otherwise …
How do you get info for an arbitrary time zone in Linux / POSIX?
Ideally, what I’d like to be able to do is take the name of a time zone and call a function to ask for its corresponding time zone info (offset from UTC, DST offset, dates for DST switch, etc.) in Linux. However, I can’t find any way to do this. The information exists in /usr/share/zoneinfo/ in th…