c

newbie questions about malloc and sizeof

Can someone explain to me why my call to malloc with a string size of 6 returns a sizeof of 4 bytes? In fact, any integer argument I give malloc I get a sizeof of 4. Next, I am trying to copy two strings. Why is my ouput of the copied string (NULL)? Following is my code: int main() { char * str = "string"; char * copy = malloc(s...

OOP Best Practices When One Object Needs to Modify Another

(this is a C-like environment) Say I have two instance objects, a car and a bodyShop. The car has a color iVar and corresponding accesors. The bodyShop has a method named "paintCar" that will take in a car object and change its color. As far as implementation, in order to get the bodyShop to actually be able to change a car object's c...

What kinds of applications are programmed in C these days?

When I was in college 20-ish years ago, C was our language of choice because at the time it was almost the only game in town as a general-purpose programming language. We learned to program using C. It was used for systems programming, data structures, operating systems, and just about everything else. Text-based console I/O was the prim...

How to build in release mode with optimizations in GCC?

Hello, What are the specific options I would need to build in "release mode" with full optimizations in GCC? If there are more than one option, please list them all. Thanks. ...

Potential problem with C standard malloc'ing chars.

When answering a comment to another answer of mine here, I found what I think may be a hole in the C standard (c1x, I haven't checked the earlier ones and yes, I know it's incredibly unlikely that I alone among all the planet's inhabitants have found a bug in the standard). Information follows: Section 6.5.3.4 ("The sizeof operator") p...

C framework like Qt ?

Hi, is there a full-featured framework for C that is similar to Qt? ...

C programming if statement

Hey guys, I know in C you can use do-while for single integers and characters but I was wondering if it is possible to use the same do-while feature for whole groups of numbers? EDIT: Okay i am really confused as to what this homework question is asking. But i think i get the question, just don't know what function will work. It wants...

Python Documentation Refers You To Docs for "the C function wait." Where is that?

There's multiple places in the Python documentation where it refers you to the C function "wait." For instance: "The exit status for the command can be interpreted according to the rules for the C function wait," in the commands and subprocess modules. Where can I find this documentation? Apparently my Google-fu is not strong enough, or...

What is the difference between memset and memcpy in C

I've read the function headers, but I'm still not sure what exactly the difference is in terms of use cases. Thanks! ...

Getting RGB values for each pixel from a raw image in C

Hello, I want to read the RGB values for each pixel from a raw image. Can someone tell me how to achieve this? Thanks for help! the format of my raw image is .CR2 which come from camera. ...

How to cycle through matrix blocks?

I have some matrix which I want to cycle through blocks, the matrix could be of many different sizes, but I can know the size, is there a way to fast cycle through blocks? i.e: to fast output the indexes of the blocks, suppose a matrix of 4*4 I should have: Block1: (0,0),(0,1)(1,0)(1,1) Block2: (0,2),(0,3)(1,2)(1,3) Block3: (2,0),(2,1)(...

FLOPS Intel core and testing it with C (innerproduct)

Hey everyone, I have some misconceptions about measuring flops, on Intel architecture, is a FLOP one addition and one multiplication together? I read about this somewhere online and there is no debate that could reject this. I know that FLOP has a different meaning on different types of cpu. How do I calculate my theoretical peak FLOP...

Developing a non-x86 Operating system

I have to choose a thesis topic soon and I was considering implementing an operating system for an architecture that is not x86 (I'm leaning towards ARM or AVR). The reason I am avoiding x86 is because I would like to gain some experience with embedded platforms and I (possibly incorrectly) believe that the task may be easier when carrie...

How to get that Zelda Text Effect?

I have a little 2D tile-based OpenGL ES game on the iPhone in which a dialogue box will appear on the screen when talking to characters in the game. I want to know how to display the text (bitmap font) gradually, not the entire string at once but, how they do it in the Zelda games, letter by letter with the little command-prompt looking ...

DHCP on busybox

Hello, I am working on embedded device who run BusyBox. The system is getting its address by using the ip command. I want to figure out from my C program whether the device ip static or received from DHCP server. How do I do that ? amit ...

Running a executable in another process without creating a new process

I want a write a program that run an executable image without creating a new process... I want to do this because I want to use plink that send a password to a remote ssh server... The plink program sends the password provided in command line .. If I use fork and exec functions someone can see the password provided in command line usin...

Visual C++ equivalent of GCC's __attribute__ ((__packed__))

For some compilers, there is a packing specifier for structs, for example :: RealView ARM compiler has "__packed" Gnu C Compiler has "__attribute__ ((__packed__))" Visual C++ has no equivalent, it only has the "#pragma pack(1)" I need something that I can put into the struct definition. Any info/hack/suggestion ? TIA... ...

How to generate Gaussian Channel in C?

I need to simulate a Gaussian Channel in C. How do I do that? Where can I get code snippets for this? ...

How should I name my class, functions, member variables and static variables?

Some may feel this question is subjective. But, I feel this is among the most important things to be told to a programmer. Is this a good function name to check for null values. 1. checkNull() 2. notNull() 3. isNull() What if I write checkIfNull() I do not know how many people share the same feeling as I do, I have spent more time...

c difference between malloc and calloc

What is the difference between doing: ptr = (char **) malloc (MAXELEMS * sizeof(char *)); // OR ptr = (char **) calloc (MAXELEMS, sizeof(char*)); ??? EDT: When is it a good idea to use calloc over malloc or vice versa? ...