c

Variables, Pointers, Objects and Memory Addresses: Why do I get this strange result?

After I thought that I've understood how they work, I tried this: NSString *str1 = [NSString stringWithCString:"one"]; NSString *str2 = [NSString stringWithCString:"two"]; NSLog(@"str1: %x, %@", &str1, str1); //bfffd3cc, one NSLog(@"str2: %x, %@", &str2, str2); //bfffd3c8, two str1 = str2; NSLog(@"str1: %x, %@", &str1, str1); //bfffd3c...

C: Reasons why a passed parameter is NULL after function call to a different module

Hello, I've a curious behavior in a C program. I pass a few arguments to a function with the following signature in a file called foo.c: foo (char *first, size_t a, size_t b, size_t c, char *last); Now, when I call this function from another C file that includes foo.h, e.g. with: foo("first value", 1, 2, 3, "last value"); in foo f...

Why does my instance variable behave so strange? Did I get it right?

For trying out some pointer stuff, I made an instance variable in an existing project. It's just declared like this: @interface PointerFun : NSObject { NSString* test; } I have no @property compiler directive, no @synthesize, so no getter and no setter. Just for testing. Then I have a method, where I try around some things with p...

Where are the best explanations of variables, pointers, references and memory addresses on the net?

Although I think that I've got that now (the light bulb is pretty bright now but still flickering a little bit), I'd like to read more stuff about pointers, variables, references, memory addresses, etc. Just the whole thing, i.e. what I have to understand when hearing thre term "reference" (think it's just a pointer, not sure). So let u...

jpg file transfer using a socket_stream in C

Hi everybody! I was wondering if sending a file with a jpg extension through a socket_stream, this automatically makes the transformation of bytes to jpg ? or need to implement some algorithm to transform the lot of bytes to image... Please could somebody explain me the way to do? ...

Marshalling C dll code into C#

I have the following C-code signature in a dll: extern __declspec(dllexport) unsigned char * funct_name (int *w, int *h, char **enc, int len, unsigned char *text, int *lp, int *mp, int *ep) The C function can modify w, h, enc, lp, mp, and ep (though the latter three can be null and it won't do anything. I'm using the following in C# ...

After K&R what book to use to learn programming in plain C?

After The C Programming Language by Brian Kernighan and Dennis Ritchie, some of the books most favoured by beginners turn out to be ones best avoided, such as anything by Herb Schildt or even the O'Reilly Practical C Programming, and there doesn't seem to be much alternative to these. Otherwise most of the material available is about C++...

How to create a Singleton in C ?

Hello, I want to create a singleton in C. What's the best way? A concurrent solution would be nice.. Edit - I am aware that C isn't the first langague you would use for a Singleton, If it was the question was much simpler. ...

Help comparing an argv string

I have: int main(int argc, char **argv) { if (argc != 2) { printf("Mode of Use: ./copy ex1\n"); return -1; } formatDisk(argv); } void formatDisk(char **argv) { if (argv[1].equals("ex1")) { printf("I will format now \n"); } } How can I check if argv is equal to "ex1" in C? Is there already a function...

How does one make a programming language?

Duplicate of: Making the perfect programming language Have you ever implemented a programming language? When is it reasonable to create my own programming language? Creating a Mobile Programming Language How to write a programming language ? Learning to write a compiler How to implement my own programming language on JVM Can anyone d...

Moving particles in C

I want to be able to move a particle in a straight line within a 3D environment but I can't think how to work out the next location based on two points within a 3D space? I have created a struct which represents a particle which has a location and a next location? Would this be suitable to work out the next location to move too? I know ...

Creating C formatted strings (not printing them)

I have a function that accepts a string ( void log_out(char *); ). In calling it, I need to create a formatted string on the fly like: int i = 1; log_out("some text%d", i); How do I do this in ANSI C? ...

Returning stack data in C; Does it unallocate correctly?

I was reviewing a friend's code and got into an interesting debate on how C/C++ allocates memory on the stack and manages its release. If I were to create an array of 10 objects in a function, but return said array, does it release when the function pops (hence making the given data invalid) or is it placed into the heap (which raises th...

K&R Exercise 2-3 "Hex to int converter" Problem.

The program I wrote works in demographics consisting of only single Hexadecimal values. (Probably not the most elegant solution, but I'm a new programmer) My question is, how would I go about handling of multiple hexadecimal digits, such as 0xAF, or 0xFF, etc? I'm not exactly sure, and I've seemed confuse myself greatly, in the attempt...

Help me to create a Makefile

Support you have a C program included by some files, and some one is consisted by some others, so as follows: ---------------------------------------- File | Included files ---------------------------------------- main.c | stdio.h, table.h ---------------------------------------- list.c | list.h -...

Undefined reference when using ncurses on linux

I'm trying to start developing a program using ncurses on Linux. I can't even get the Hello World example to compile. Here's the code: #include <curses.h> int main() { initscr(); printw("Hello, world."); refresh(); getch(); endwin(); return 0; } When I attempt to compile, I get:...

How do I create a "netlink" between kernel and userspace?

Now I want to create a netlink which is used to communicate between the user and kernel space. My Linux kernel version is 2.6.28. the following is my wrong code: nf_sock=netlink_kernel_create(NL_PROTO,0,nl_user_skb,THIS_MODULE); The error message is briefly as: error: too few arguments to function 'netlink_kernel_creat' In the file...

Format disk and create partition in C on LynxOS

Can you explain to me how I can do a mini program that does a system call in C in order to format the disk and create a new partition? O/S is LynxOS. ...

What C-integration problems arise with stackless VM implementations?

By stackless VM I mean implementation which maintains its own stack on the heap instead of using system "C-stack". This has a lot of advantages like continuations and serializable state, but also has some disadvantages when it comes to C-bindings, especially to C-VM-C kind of callbacks (or VM-C-VM). The question is what exactly these di...

C++ Macros: manipulating a parameter (specific example)

I need to replace GET("any_name") with String str_any_name = getFunction("any_name"); The hard part is how to trim off the quote marks. Possible? Any ideas? ...