Say I have code like this... typedef struct { unsigned A:1; unsigned B:1; } FlagStruct; extern FlagStruct *Flags; Imagine that the Flags instance is a shared resource in a multi-threaded application. Say thread #1 decides to read the value of Flags->A but thread #2 decides to set or clear Flag->B at the exact same time. How isolated is Flag->A from Flag->B such that any changes to Flag->B does not affect the value of Flag->A? In other words, are set or clear operations in this structure atomic and therefore thread safe?

Member Avatar
Member Avatar
+0 forum 4

I am importing some C code into a C++ compiler, specifically Borland C++ Builder 5. I seem to have a problem with this style of code: // A structure that contain's itself typedef struct AnObject AnObject; struct AnObject { AnObject *Object; }; // A global structure to store a pointer of the AnObject structure typedef struct { AnObject *Page; } _Stock; _Stock Stock; // A function that returns an instance of AnObject AnObject *CreateInstance() { return malloc(sizeof(AnObject)); } // A function that copies the generated instance to the global pointer void somefunct() { // The pointer will start off NULL …

Member Avatar
Member Avatar
+0 forum 7

Lets say I have a shared library in Linux, written in C, with a single function that simply returns the pointer to a string literal. [code]void *ReturnObject() { return (void *)"\xFA\x03\x44\x10\xE0"; }[/code] When this library is loaded by the host application at runtime and this function is called, is the returned pointer pointing to some place in RAM or to the binary file on disk? Is RAM ever involved in this situation other than storing the pointer itself? I ask because I plan on implementing this sort of thing in my project and the string will be several megabytes in …

Member Avatar
Member Avatar
+0 forum 15

I am designing a project geared towards business and is built in C language. The design of the various interface screens are currently in XML/CSS. The target platform is a PC running linux or windows. To compile the software, I first run a source-to-source compiler which converts the XML/CSS into C code, and then compiles that to the final product. This source-to-source compiler was also designed by me and written in C. I am looking for a scripting language which could be embedded into the source-to-source compiler that allows for the following things: - Code that is easy to read …

Member Avatar
Member Avatar
+0 forum 3

I am developing an OpenGL application (mostly 2D Ortho) compiled in gcc. As a requirement, in order to offer remote online tech support for the application, I need to be able to view and control this application remotely from time to time using something like VNC viewer. I tried using vnc with the application but found it impossible to work with. In my first experiment, I was able to view the remote computer but it was absolutely impossible to use because the vnc server was sending random blocks of random snapshots of various stages of frame redraw, so you would …

Member Avatar
Member Avatar
+0 forum 2

I have been coding in C for a very long time, and I thought I had it all figured out, until I saw this code in an MD5 library: [code] static void MDPrint (mdContext) MD5_CTX *mdContext; { int i; for (i = 0; i < 16; i++) printf ("%02x", mdContext->digest[i]); } static void MDString (inString) char *inString; { MD5_CTX mdContext; unsigned int len = strlen (inString); MD5Init (&mdContext); MD5Update (&mdContext, inString, len); MD5Final (&mdContext); MDPrint (&mdContext); printf (" \"%s\"\n\n", inString); } [/code] I am using gcc to compile it in Linux, and it works fine. The part that surprised me …

Member Avatar
Member Avatar
+0 forum 5

I have a weird problem and I want to know if any of you have any ideas on how to fix this. If I do this... [code] swprintf(Dest, 500, L"G%sY", "AMEDA"); [/code] [b](wchar_t*)Dest[/b] contains the following text... [TEX]GAMEDAY[/TEX] But if I do this... [code] swprintf(Dest, 500, L"G%sY", L"AMEDA"); [/code] [b](wchar_t*)Dest[/b] now contains... [TEX]GAY[/TEX] So it seems that the compiler is converting the text to a wide character array, but [b]swprintf()[/b] still thinks that [b]%s[/b] is pointing to a simple character array. I've tried this too... [code] swprintf(Dest, 500, L"G%sY", (const wchar_t *)L"AMEDA"); [/code] Same thing happens. I know this is …

Member Avatar
Member Avatar
+0 forum 16

What do you guys think is a good way to deal with this situation: [code] #define TYPE_INT 0 // 4 byte, signed #define TYPE_CHAR 1 // 1 byte, signed #define TYPE_UINT 2 // 4 byte, unsigned #define TYPE_FLOAT 3 // 4 byte, signed, floating point typedef struct { float Value; // This value can be of any type, but initially stored in a float int Type; } AnyVal; void main() { // The value is loaded by some function, it can have a value of any type in it AnyVal *Val = LoadVal(); // Now do some math with that …

Member Avatar
Member Avatar
+0 forum 7

Hello, I have a problem with compiling my code... Platform: [b]Ubuntu Linux 10.04[/b] Compiler: [b]gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3[/b] IDE: [b]Netbeans 6.9.1[/b] My C program is required to exclusively deal with Unicode. I can use these functions just fine: [b][COLOR="Green"]wcscpy(), wcslen(), mbstowcs(), wcstombs(), snprintf()[/COLOR][/b] The problem seems to only be when I use this function: [b][COLOR="Red"]swprintf()[/COLOR][/b] Here are the headers I am including in the order I am including them: [code] #include <stdlib.h> #include <string.h> #include <math.h> #include <stdio.h> #include <wchar.h> #include <wctype.h> [/code] This is the line of code which gives me an error: [code] ret = __builtin_apply( (void *)swprintf, …

Member Avatar
Member Avatar
+0 forum 6

The End.