c

How does ruby's rb_raise stop the execution of the c function calling it?

If you write a ruby method as a function in C that uses rb_raise, the part of the function after the call will not get excecuted and the program will stop and you will think that rb_raise used exit(). But if you rescue the exception in ruby, like: begin method_that_raises_an_exception rescue end puts 'You wil still get here.' The ru...

Higher order functions in C

Is there a "proper" way to implement higher order functions in C. I'm mostly curious about things like portability and syntax correctness here and if there are more than one ways what the merits and flaws are. Edit: The reason I want to know how to create higher order functions are that I have written a system to convert PyObject lists...

How do you removing a cycle of integers (e.g. 1-2-3-1) from an array

If you have an array of integers, such as 1 2 5 4 3 2 1 5 9 What is the best way in C, to remove cycles of integers from an array. i.e. above, 1-2-5-4-3-2-1 is a cycle and should be removed to be left with just 1 5 9. How can I do this? Thanks!! ...

Questions on usages of sizeof

Question 1 I have a struct like, struct foo { int a; char c; }; When I say sizeof(foo), I am getting 8 on my machine. As per my understanding, 4 bytes for int, 1 byte for char and 3 bytes for padding. Is that correct? Given a struct like the above, how will I find out how many bytes will be added as padding? Question 2 I am...

Linking the Linker script file to source code

Hello , I am new to GNU compiler. I have a C source code file which contains some structures and variables in which I need to place certain variables at a particular locations. So, I have written a linker script file and used the __ attribute__("SECTION") at variable declaration, in C source code. I am using a GNU compiler (cygwi...

its about the label Associated with the text box.

i have a label and a text box associated to it . I have added some text in text box which is invisible at first... now I want to display the content after the cursor moves on the label... plz give me the code for the same.. ...

dynamic linking:change of the linking path.

Normally it happens that when ever the path of the library that has to be linked dynamically is defined in LD_LIBRARY_PATH or it it will be mentioned with -L flag while creating the binary. In actual scenario if ,lets say the binary has been built and deployed at the client place. Now if there is a change in the path of one of the dyn...

What is the modern equivalent (C++) style for the older (C-like) fscanf method?

What is the best option if I want to "upgrade" old C-code to newer C++ when reading a file with a semicolon delimiter: /* reading in from file C-like: */ fscanf(tFile, "%d", &mypost.nr); /*delimiter ; */ fscanf(tFile, " ;%[^;];", mypost.aftername);/* delimiter ; */ fscanf(tFile, " %[^;]", mypost.forename); /*delimiter ; */ fscanf(tFil...

How to implement a set ?

I want to implement a Set in C. Is it OK to use a linked list, when creating the SET, or should I use another approach ? How do you usually implement your own set (if needed). NOTE: If I use the Linked List approach, I will probably have the following complexities for Set my operations: init : O(1); destroy: O(n); insert: O(n); remo...

Single line comment - unable to compile on solaris

I'm trying to compile a C program on Solaris. It's complaining on lines having comments starting with //. I'm new to solaris. Please suggest a solution. ss0iconv.c // This is line 193 Output: src/c_asm/sol/ss0iconv.c", line 193: syntax error before or at: / ...

Checking status after wait()

After creating a child process and exiting it immediately (_exit()), I want to perform a wait and check the status. Now I wonder if in the 'else' branch of the if/else construct I also need to check for WIFSIGNALED. As far as I understand, if I perform a wait, a) an error could have occured (-1), the child could have terminated normally ...

Exemple where TYPE_ALIGNMENT() fails

Hi, I have a question relating to alignment in c/c++. In http://stackoverflow.com/questions/364483/determining-the-alignment-of-c-c-structures-in-relation-to-its-members Michael Burr posted this Makro: #define TYPE_ALIGNMENT( t ) offsetof( struct { char x; t test; }, test ) in the comments someone wrote this might fail with non POD ...

C question about pointers and arrays

char a[]="HELLO"; char *p="HELLO"; will a[2] and p[2] fetch the same character? ...

Whats the problem with int *p; *p=23;

Yesterday in my interview I was asked this question. (At that time I was highly pressurized by so many abrupt questions). int *p; *p=23; printf("%d",*p); Is there any problem with this code? I explained him that you are trying to assign value to a pointer to whom memory is not allocated. But the way he reacted, it was like I am wron...

Ways to divide the high/low byte from a 16bit address?

Hello, I'm developing a software on 8051 processor. A frequent job is to divide the high and low byte of a 16bit address. I want to see there are how many ways to achieve it. The ways I come up so far are: (say ptr is a 16bit pointer, and int is 16bit int) [note the rn and arn is registers] bitwise operation ADDH = (unsigned int) ptr ...

Passing Structures by Reference? [C]

I am trying to create a linked list, with two seperate lists in one structure. That is, it holds a 'name' and a 'age' value. Then the program can either output the list sorted by name, or sorted by age. So i need two linked lists, essentially. However, i need the program to be aware of the root/head of both the name list and the age lis...

Command line tool (PDF Workflow) in OSX that detects if key is down

Hello! I'm writing a OSX PDF Workflow in ObjC and C. A single executable ("UNIX Tool" as named in the Apple reference), that reads in the spooled PDF file, does some parsing. I'd like to give more functionality by enabling a key-down event handling, meaning - when user opens print dialog in an application - and chooses to left-mouse-cl...

C++ ulong to class method pointer and back

Hi guys, I'm using a hash table (source code by Google Inc) to store some method pointers defined as: typedef Object *(Executor::*expression_delegate_t)( vframe_t *, Node * ); Where obviously "Executor" is the class. The function prototype to insert some value to the hash table is: hash_item_t *ht_insert( hash_table_t *ht, ulong ke...

How to detect defunct processes on Linux?

I have a parent and a child process written in C language. Somewhere in the parent process HUP signal is sent to the child. I want my parent process to detect if the child is dead. But when I send SIGHUP, the child process becomes a zombie. How can I detect if the child is a zombie in the parent process? I try the code below, but it does...

[GCC, linking] How to link app with static library + why this is not working

I have a problem. I wrote example code and I want to build it without the error: main.cpp(.text+0x5): undefined reference to `test()' Library test1.c #include <stdlib.h> void test() { puts("Działa"); } test1.h #ifndef TEST1_H #define TEST1_H extern void test(); #endif makefile all: gcc -c ./src/test1.c -o ./lib/test1.o ...