c

How do I use some specific dll in c/c++?

Like the msvcr70/msvcr80/msvcr90.dll, what's the code like to instruct the linker to link to one of them dynamically? Or has that anything to do with c/c++,but cmake? ...

multiple definition of inline function

Hi, I have gone through some posts related to this topic but was not able to sort out my doubt completely. This might be a very naive question. I have a header file inline.h and two translation units main.cpp and tran.cpp. Details of code are as below inline.h #ifndef __HEADER__ #include <stdio.h> extern inline int func1(void) { re...

Bidirectional FIFO

I would like to implement a bidirectional fifo. The code below is functioning but it is not using bidirectional fifo. I have searched all over the internet, but haven't found any good example... How can I do that? Thanks, WRITER.c: #include <stdio.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/wa...

do you have to get rid of the WinMain to turn a project into a lib

say I built an application called App1 with a lot of classes in a single project. And I decide that I want to build another project called App2 and I want to use those same classes so I decide to turn App1 into a lib file. Must I remove the WinMain function to do so or can I leave it and the compiler will ignore the winMain in the lib fi...

why do game engines prefer static libraries over dynamic link libraries

I've been reading a few gaming books. And they always prefer to create the engine as a static library over dynamic link. I am new to c++ so I am not highly knowledge when it comes to static libraries and dynamic link libraries. All I know is static libraries increase the size of your program, where DLL link libraries are loaded as you ne...

How to parse a string into a datetime struct in C?

I would like to have a string (char*) parsed into a tm struct in C. Is there any built-in function to do that? I am referring to ANSI C in C99 Standard. ...

turning a project into a static library

I checked out the microsoft documents. it shows how to create a static library upon creation of the project. but not necessarily on how to convert a previously made project, into a static library. So my question is, where do I go to turn my previously made project, into a static lib. so I can include it in my other projects ...

Help understanding Reverse Polish Notation for homework assignment?

I have been asked to write a simple Reverse Polish Notation calculator in C as part of a homework assignment. I'm having difficulty understanding RPN. Can you please help me understand Reverse Polish Notation? Also, any tips on how to approach this problem would be greatly appreciated. ...

How to detect if the Windows DWORD_PTR type is supported, using an ifdef?

There are some new integer types in the Windows API to support Win64. They haven't always been suppoprted; e.g. they aren't present in MSVC6. How can I write an #if condition to detect if these types are supported by <windows.h>? (My code needs to compile under many different versions of Microsoft Visual C++, including MSVC6. So I ne...

Killing a Windows process created with _spawnl

I have some code that uses _spawnl to spawn a process. It works great. However, we've run into a problem where that process hangs and we want to kill it. Given the PID (as in the # that appears in task manager), I can get the handle to the process using OpenProcess. As far as I can tell, this just returns the exactly same value that ...

Where does getopt_long store an unrecognized option?

When getopt or getopt_long encounters an illegal option, it stores the offending option character in optopt. When the illegal option is a long option, where can I find out what the option was? And does anything meaningful get stored in optopt then? I've set opterr = 0 to suppress the automatically printed error message. I want to create...

Reading bytes from a text file that has the form of machine code in C?

I have a text file with machine code in this form: B2 0A 05 B2 1A 01 B3 08 00 17 B2 09 18 where an instruction has this format: OP Mode Operand Note: Operand could be 1 or 2 bytes. Where:(example) OP = B2 Mode = 0A Operand = 05 How can I read the bytes in a variable? As shown in the above example. When i read the file I g...

c program pointer

Hello , I am trying some programs in c face a problem with this program can any one tell me what is the problem with this and i also want to know that when in the above case if the pointer value is incremented then will it over write the previous value address as #include<stdio.h> int main() { int a=9,*x; float b=3.6,*y; c...

Setting the first two bytes of a block of memory as a pointer or NULL while still accessing the rest of the block

Suppose I have a block of memory as such: void *block = malloc(sizeof(void *) + size); How do I set a pointer to the beginning of the block while still being able to access the rest of the reserved space? For this reason, I do not want to simply assign 'block' to another pointer or NULL. ...

Setting shadowColor with property syntax gives compiler error: Expected identifier before '[' token.

I have an iPad app in which I'm setting the shadow color of a UILabel in a UIView's initWithFrame: method. When I use the following syntax: m_label.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.5]; I get this compiler error: Expected identifier before '[' token However, when I use the following syntax: [m_label setShadowColor:[...

Using ptrace to generate a stack dump

Hello. I am compiling C++ on *nix and I would like to generate a stack dump a) at an arbitrary point in the program, b) during any signal, particularly during SIGSEGV. Google tells me that ptrace is probably the tool for the job, but I can't find any comprehensible examples of walking the stack. Getting the return address, yeah, but wh...

Works for Short Input, Fails for Long Input. How to Solve?

I've this program which finds substring in a string. It works for small inputs. But fails for long inputs. Here's the program: //Find Substring in given String #include <stdio.h> #include <string.h> main() { //Variable Initialization int i=0,j=0,k=0; char sentence[50],temp[50],search[50]; //Gets Strings printf("Enter Sentence...

How to @synthesize a C-Style array of pointers?

I have a property defined in a class like so: @interface myClass UIImageView *drawImage[4]; ... @property (nonatomic, retain) UIImageView **drawImage; ... @synthesize drawImage; // This fails to compile I have found similar questions on StackOverflow and elsewhere, but none that really address this issue. What is the most Objective-C...

Is there a way to make C macros keyword agnostic?

Is there a way to concatenate keywords in a macro and get C to behave in a more dynamic fashion as in: #define macro(fun,ction,var,iable) function(variable) I know this kind of thing exists in other languages. ...

strstr and occurrences to match

I have several possible occurrences to test with strstr. if ((a = strstr(string, "FOO")) != NULL || (a = strstr(string, "BAR")) != NULL || (a = strstr(string, "FOO2")) != NULL ||(a = strstr(string, "BAR2")) != NULL || (a = strstr(string, "FOO3")) != NULL ||(a = strstr(string, "BAR3")) != NULL) // do something and then based on...