c

what is `int *arr[3][4]` pointing to?

I am modifying some code and came across a declaration that I am having trouble understanding: int *arr[3][4] = {0}; What exactly is this pointing to? Is it a matrix where every element is a pointer? Or is it pointing to a matrix of size [3][4]? Thanks ...

What is the best way to call C/C++ code from other languages such as Java, PHP, Perl, Python, etc?

What is the best way to call C/C++ from other languages such as Java, Python, Perl, PHP, etc? ...

Python ctypes and function calls

My friend produced a small proof-of-concept assembler that worked on x86. I decided to port it for x86_64 as well, but I immediately hit a problem. I wrote a small piece of program in C, then compiled and objdumped the code. After that I inserted it to my python script, therefore the x86_64 code is correct: from ctypes import cast, CFU...

mysql c api row[0] to string

When using MYSQL C API to query results. The results are returnd as a MYSQL_ROW type, which according to the MYSQL C API documentation, I can easily printf("%s", row[0] ). But what if I want to transfer the contents of row[0] into a string or a char*? ...

gdb executable file format

I'm trying to use GDB to debug (to find an annoying segfault). When I run: gdb ./filename from the command line, I get the following error: This GDB was configured as "i686-pc-linux- gnu"..."/path/exec": not in executable format: File format not recognized When I execute: file /path/executable/ I get the following info: ELF ...

Has the daylight savings rule change invalidated the C runtime library?

Some time ago I put together a time based library that could be used for working out relative times within a year for someone. I noted at the time, that it did the one hour shift in both directions for daylight savings. It just occurred to me that Congress changed the daylight savings time rules. I don't recall seeing any information...

Most efficient way to list items in C/C++

I have a list of say 100 unsorted items. Each item belongs to a group. The group the item belongs to is simply a member of the item class. Using C/C++ I'm looking for the most efficient way of scanning through the list of items, checking which group they are in and printing the item to the screen. Here's the catch though. Once an item f...

What's the best way to do a backwards loop in C/C#/C++?

I need to move backwards through an array, so I have code like this: for (int i = myArray.Length - 1; i >= 0; i--) { // Do something myArray[i] = 42; } Is there a better way of doing this? Update: I was hoping that maybe C# had some built-in mechanism for this like: foreachbackwards (int i in myArray) { // so easy } Up...

How to structure #includes in C

Say I have a C program which is broken to a set of *.c and *.h files. If code from one file uses functions from another file, where should I include the header file? Inside the *.c file that used the function, or inside the header of that file? E.g. file foo.c includes foo.h, which contains all declarations for foo.c; same for bar.c and...

What is the full "for" loop syntax in C (and others in case they are compatible) ?

I have seen some very weird for loops when reading other people's code. I have been trying to search for a full syntax explanation for the for loop in C but it is very hard because the word "for" appears in unrelated sentences making the search almost impossible to Google effectively. This question came to my mind after reading this thr...

Checking if something was malloced

Given a pointer to some variable.. is there a way to check whether it was statically or dynamically allocated?? ...

Professional #include contents

I need to create an API that will allow my customer's developers to use a proprietary C module that will be released as a library (think .lib or .so -- not source). I'd like to make the header as developer-friendly as possible (so I won't need to be), following best practices and providing comments with descriptions, examples, caveats, ...

return 0 implicit

The last week on the ACM ICPC Mexico competition, I missed a "return 0" on a C++ program. For this reason we got punished with 20 minutes. I had read that the standard does not oblige us to write it at the end of a main function. It is implicit, isn't it? How can I prove it? We were using a Fedora system with a G++ compiler. ...

String Padding in C

I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000". char *StringPadRight(char *string, int padded_len, char *pad) { int len = (int) strlen(string); if (len >= padded_len) { return string; } int i; for (i = 0; i < padded_len - len; i++) { strcat(string, pad); ...

OpenGL include directives on OS X

I am a bit confused why this code compiles. I leave out the "necessary" #include <OpenGL/gl.h> and still the program can compile. How is this possible when my program is calling functions from the GL library, without including them. int main(int argc, char** argv) { glClearColor(1.0,1.0,1.0,1.0); return 0; } I use this comp...

C/C++ source file after preprocessing

Let's say I have a source file with many preprocessor directives . Is it possible to see how it looks after the preprocessor is done with it ? ...

C Vs Lisp Conceptually

I was wondering for a while about this topic and i would like to hear some opinions from the community. What i am wondering about is how to explain to a non-programmer the conceptual difference between a language like C and a language like Lisp. What I find challenging about this is to translate the knowledge of the language itself into ...

gcc compiler: How do I enable C++ styled comments while leaving ANSI enabled

This has just come up as a question where I worked so I did a little digging and the answer is a ExpertsExchange one. So I hand you over to the original question asker, Manchung: I have a project written in pure C which is to be used in embedded system. So, I use pure C to minimize the code size. When I compile the project, I us...

How to identify the file content is in ASCII or binary?

How to identify the file content is in ASCII or binary file using c++? ...

How can I use SQLite to open a database from memory?

It looks like all the methods for loading SQLite involve loading from a named file using a string. I would like to load SQlite database from memory. The database is already loaded into memory. ...