c

C: warns about implicit long to int conversion

Hi, I was wondering whether there is a way to tell the compiler (I'm on gcc version 4.1.2 20080704 (Red Hat 4.1.2-46) or icc 11.1) to throw a warning whenever a long-to-int implicit conversion takes place. For example, compiling the file test.c which contains the code: #include <stdio.h> #include <stdlib.h> int main(int argc, char** a...

Buffer size in C

When provided with a buffer size in C, how do I know how much is left and when do I need to stop using the memory? For example, if the function I am writing is this: void ascii_morse (lookuptable *table, char* morse, char* ascii, int morse_size) { } In this application I will be passed a string (ascii) and I will convert it to morse...

How to resolve this Shift/Reduce conflict in YACC

I have a grammar like this: "Match one or more rule1 where rule1 is one or more rule2, where rule2 is one or more rule3, etc. etc. each seperated by newlines". Look at the following example. start: rule1_list ; rule1_list: rule1 | rule1_list NEWLINE rule1 ; rule1: rule2 | rule2 NEWLINE rule3...

'Enter' as an input?

Here is my code!(sorry for my poor english) #include<stdio.h> int convert(char ch); int main(void) { char ch=0; while(ch != 'q') { ch=getchar(); ch=convert(ch); if(ch == -1) printf("wrong input"); else putchar(ch); putchar('\n'); } return 0; } int convert(char c...

Interface 'go' with C libraries

How does one interface a 'go' program with a C library? I've been browsing go's source code but I still didn't figured it out. If someone has already done so, could you share, please? UPDATED: Thanks to @fserb, I am posting some documentation from the 'go' sources: Cgo enables the creation of Go packages that call C code. Us...

Is a Binary Tree Contained Within Another Binary Tree - C

Hello party people...So I just had an interview that I'm confident I screwed up royally. I had a bunch of questions thrown at me and didn't have enough time to answer the last one. After getting all beginning questions correct, I was asked to write a function that would determine whether a binary tree b is contained within another bina...

GCC memory leak detection equivalent to Microsoft crtdbg.h?

After many years of working on a general-purpose C++ library using the Microsoft MSVC compiler in Visual Studio, we are now porting it to Linux/Mac OS X (pray for us). I have become accustomed and quite fond of the simple memory leak detection mechanism in MSVC: #ifdef DEBUG #define _CRTDBG_MAP_ALLOC #define NEW new( _NORMAL_B...

Linux socket value

I have a client-server program, on the server side: sockListen = socket(PF_INET, SOCK_STREAM, 0); socketListen always seems to equal 3. Why? how about 0, 1 or 2? What is the value range of sockets in Linux? ...

Nested struct variable initialization

How can I initialize this nested struct in C? typedef struct _s0 { int size; double * elems; }StructInner ; typedef struct _s1 { StructInner a, b, c, d, e; long f; char[16] s; }StructOuter; StructOuter myvar = {/* what ? */ }; ...

How to call a flex parser in c

How to call a flex parser in c ? ...

How can I implement 'tee' programmatically in C?

I'm looking for a way in C to programmatically (ie, not using redirection from the command line) implement 'tee' functionality such that my stdout goes to both stdout and a log file. This needs to work for both my code and all linked libraries that output to stdout. Any way to do this? ...

How to ignore your own broadcast udp packets

For the following I'm assuming one network card. I have a component of my program which is designed to let others in the subnet know of its existence. For this, I've implemented a solution where whenever the program starts up (and periodically afterwards) it sends a broadcast to INADDR_BROADCAST - whoever listens on the required port w...

How to combine shared libraries?

I've got some .so libraries that I'd like to combine into one shared library so that it doesn't depend on the original .so files anymore. The .so files have dependencies to each other. How can I do this? Can I do this? ...

Client/Server: Integer always received as 1 (C-programming)

Hi! I'm building a client and a server program that exchanges data over TCP and I'm having trouble sending an ACK-confirmation from the server back to the client when an operation is successfull. I've managed to send a struct with various members from the client to the server, then the server should respond by sending an integer confirm...

Removing null warnings in Splint

I have been trying out Splint with a C program I recently wrote and trying to understand and remove the warnings it gives. One I understand but can't understand how to remove it comes from the following code snippet: static MyType_t *findById(const int id) { int i; for (i = 0; i < MY_ARR_SIZE; i++) { if (my_arr[i].i...

What are the effects of incorrectly setting the netmask?

What are the effects of incorrectly setting the netmask? I have a C++ application that sets the network mask of a device. If the netmask is set incorrectly, tftp doesn't seem to work properly. Why would this happen? What other problems occur when the netmask is not properly set for a device/PC? ...

[C] Syntactic errors

I'm writing code for the exercise 1-24, K&R2, which asks to write a basic syntactic debugger. I made a parser with states normal, dquote, squote etc... So I'm wondering if a code snippet like /" text " is allowed in the code? Should I report this as an error? (The problem is my parser goes into comment_entry state after / and ignore...

c++ Mysql C API Connection Question

I'm building an application which uses Mysql, I was wondering what would be the best way to manage the connection to the actual Mysql server? I'm still in the design phase, but currently I have it Connecting (or aborting if error) before every query and disconnecting after which is just for testing as right now I'm only running 1 query ...

How to refresh image in gtk ?

Sorry everyone my english is poor , i'm still learning. Let me say this as plainly as I can this is my question. if i create a application , like this. -------------------------------- image 1|image 2|image 3| (button) -------------------------------- i wanna if i clicked button,the application image will be change -----------------...

how do I always include symbols from a static library?

Suppose I have a static library libx.a. How to I make some symbols (not all) from this library to be always present in any binary I link with my library? Reason is that I need these symbols to be available via dlopen+dlsym. I'm aware of --whole-archive linker switch, but it forces all object files from library archive to linked into resu...