I've seen this done in C before:
#define MY_STRING "12345"
...
#define SOMETHING (MY_STRING + 2)
What does SOMETHING get expanded to, here? Is this even legal? Or do they mean this?:
#define SOMETHING (MY_STRING[2])
...
Hello, I found here a script which converts obj files into C header files with information required to render the model with OpenGL. I'd like something like this but I will need texture coordinates as well. The tool apparently doesn't do that.
Such a tool will save me a lot of time because I'd have to make my own program to extract data...
Say we have
typedef struct {
int value1;
int value2;
} values_t;
and
values_t* values;
is filled with values[i].value1 and values[i].value2 pairs that may or may not be unique.
and we want to fill
values_t* values_unique;
only with unique pairs from values, in the order they first appear in values.
What is the ideal way ...
I need to detect a keystroke, without the user pressing enter. What's the most elegant way?
I.e. If the user hits the letter Q, without pressing enter, the program does something.
...
I am writing an assembly function to be called from C that will call the sidt machine instruction with a memory address passed to the C function. From my analysis of the code produced by MSVC10, I have constructed the following code (YASM syntax):
SECTION .data
SECTION .text
GLOBAL _sidtLoad
_sidtLoad:
push ebp
mov ...
typedef struct _DListNode
{
struct _DListNode* prev;
struct _DListNode* next;
void* data;
}DListNode;
in gcc :
DListNode *p = NULL;
p = (DListNode*)malloc(sizeof(DListNode));
p->data = (int*)malloc(sizeof(int));
scanf("%d", (int*)p->data);
compile correctly.
in gcc :
DListNode *p = NULL;
p = (DListNode*)malloc(...
i have a c program that relies on a second library whose compilation i can control. i want to be able to compile my program into a shared object library without it linking to the second library. in other words i want a single monolithic shared object library at the end. how can i do this?
if i separately compile the second library into ...
Hi, after reading about sequence points, I learned that i = ++i is undefined.
So how about this code:
int i;
int *p = &i;
int *q = &i;
*p = ++(*q); // that should also be undefined right?
Let's say if initialization of p and q depends on some (complicated) condition.
And they may be pointing to same object like in above ca...
Hi, Silly question from a new C programmer... I get a segmentation fault in the following code:
#include <stdio.h>
int main(void)
{
double YRaw[4000000]={0};
return 0;
}
Using GDB, I get the following comment:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00007fff5dd7b...
This code is for Microchip's PIC32MX microprocessor. Their compiler is essentially GCC 3.4.
I tend use GCC's __packed__ attribute to pack bitfields into a union, and later retrieve them as an unsigned char (ie. type-punning) for sending over SPI or I2C. This behaviour is all defined by my implementation, and works perfectly. I prefer th...
I'm doing C programming and need help with this problem..
char str[] = "Hello";
char * ptr = str;
char ** ptr2 = (char**)ptr;
I have these three lines in a header file. The first two lines are fine but an error will occur in the third line. Explicitly the error is "initializer element is not constant".
Is there any other way of assig...
Quite a newbie question as is.
...
I have a 2-dimensional array of pointer to char and initialising it in a header file.
The problem is this: it doesn't complain getting assigned a const char[] but does not like me assigning const char* (as shown in the code). It gives me an error "initializer element is not constant".
const char lang[8] = "English";
const char * langPt...
So I've got an app which compiles fine on windows, linux and a few variations of unix. I recently decided to port it to OSX when I ran into a snag.
I have a template which looks like this:
template<int (&F)(int)>
int safe_ctype(unsigned char c) { return F(c); }
the idea being to prevent sign extension from crashing certain implementa...
How do I diassemble a an object program made on C(linux)?
Can anyone please help me with the command line.
...
What does this error mean?
/tmp/ccevEqoI.o: In function `main':
funcptr.c:(.text+0x61): undefined reference to `AddALL'
collect2: ld returned 1 exit status
I'm trying to write a function which adds all the integers up to the limit
entered by the user.
Transcribed 'answer' which is a comment from the OP:
I wrote a program that ...
I am totally new to assembly; currently i am trying to convert the undermentioned assembly code execution to windows equivalent but not even getting a single hint. Any help in porting the undermentioned code in asm block to windows equivalent will be highly appreciated.
void cpuid(uint32_t idx,
uint32_t *eax,
...
Hi,
Can some one help me to understand how memmove is implemented in C. I have only one special condition right ?
if((src<dst)&&((src+sz) > dst))
copy from the back
Also does it depend on the way stack grows ?
...
Hi
I heard in little endian, the LSB is at starting address and in Big endian MSB is at starting address. SO I wrote my code like this. If not why ?
void checkEndianess()
{
int i = 1;
char c = (char)i;
if(c)
cout<<"Little Endian"<<endl;
else
cout<<"Big Endian"<<endl;
}
...
Please share with us your favorite, and most general, PRINT or DEBUG macro
applicable to all (or almost all) variables in different types and to arrays in C. The macro
can have any number of parameters (though 1-3 are preferred); if it increases
descriptive power at all, C99 features can be assumed.
#define PRINT(var, ...) \
...
L...