Hi.
Here is what i have and I wonder how this works and what it actually does.
#define NUM 5
#define FTIMES(x)(x*5)
int main(void)
{
int j = 1;
printf("%d %d\n", FTIMES(j+5), FTIMES((j+5)));
}
It produces two integers: 26 and 30.
But i can't seem to understand how it makes this possible..
Thanks.
...
Callbacks in VB (from C dll).
I need to pass a vb function as a callback to a c function in a dll. I know I need to use
addressof for the function but I'm getting more and more confused as to how to do it.
Details:
The function in the dll that I'm passing the address of a callback to is defined in C as :
PaError Pa_OpenStream( PaSt...
I have a function that accepts a char* as one of its parameters. I need to manipulate it, but leave the original char* intact. Essentially, I want to create a working copy of this char*. It seems like this should be easy, but I am really struggling.
My first (naive) attempt was to create another char* and set it equal to the original...
How long should it take an average coder (has used C/C++ but isn't an expert) to understand what a buffer overflow is, why its a bad thing, and how someone might use it to take control of the application?
...
Hi all,
I noticed using task manager that the following code has a GDI leak in it. The count of GDI object in the process executing this code increases by 1 each time it executes however I can't seem to find the problem.
Any help would be appreciated.
// create new DC based on current
HDC hDC = CreateCompatibleDC(GetDC());
// sele...
I recently became aware that the strdup() function I've enjoyed using so much on OS X is not part of ANSI C, but part of POSIX. I don't want to rewrite all my code, so I think I'm just going to write my own strdup() function. It's not that hard, really, it's just a malloc() and a strcpy(). Anyway, I have the function, but what am I doing...
Since C++ seems to have all of C's features, why learn C over C++?
...
I am trying to build a windows console application without using the C runtime (msvcrt or libcmt). That is to link just against kernel32.lib and use console functions from WIN32 API instead of printf and such.
My problem is that during link the compiler fails to find __alldiv which seems to handle 64 bit integer divides in 32 bits appli...
i have a function like
void printMe (void *i)
{
printf("%d", i);
}
where i want to pass a void pointer and print it to screen.
The above example is fine if the i is integer, float or double but crashes if i is a char. There is no overloading in C like i usually use in C++.
So the question is this, can we create a function in C tha...
On linux, I am opening a pseudo tty on the master side. While there is no client on the slave side, the pseudo tty seems to be echoing everything I am writing to him, which is not what I am expecting.
Consider the folowing code :
int main(int argc, char * argv[])
{
int ptyfd;
int rc; /* return code */
char readbuf[3];
...
Hello,
This code doesn't appear to be correct in ANSI-C, but ok in C99 :
struct a { int x; int y; } z;
What are the differences about struct in C99 and ANSI-C ?
Edit: I forgot the "a", my bad. This code compiles ok with gcc in C99 mode, but is a parse error on splint, which is known to not support all the C99 extensions.
Edit2: here...
Hi!
I recently finished a university course in C. Therefore I lack experience, of course.
Some universities tend to teach their students secure programming, or at least some elements. There's even a video (taken from here).
Being in C, copying strings, requires - as far as I know - strcpy or string.h functions. How do you use it secu...
How to write a Reader/Writer lock with timeout, using conditional variables in C/C++?
...
Hi,
I am attempting to copy the members of a struct containing a mixture of ints, char's and arrays of chars into a byte array to send to a serial line. So far I have
// struct msg_on_send
// {
// char descriptor_msg[5];
// int address;
// char space;
// char cmdmsg[5];
// char CR;
// char LF;
// };
/...
We try and embed a what string within binary objects so that we can see the version number for an executable or shared library that has been deployed. Typically we embed standard CVS Id information in this what string. For example, we might embed:
const char cvsid[] = "@(#)OUR_TEAM_staging_remap_$Revision: 1.30 $ $Name: $";
within th...
Hey!
I had this idea of creating a count down timer, like 01:02, on the screen (fullsize).
One thing is that I really don't have a clue on how to start.
I do know basic c/c++, win32 api and a bit of gdi.
Anyone have any pointers on how to start this? My program would be like making the computer into a big stopwatch (but with added fe...
In C/C++, are global variables as bad as my professor thinks they are?
...
I saw this question asking about whether globals are bad.
As I thought about the ramifications of it, the only argument I could come up with that they're necessary in some cases might be for performance reasons.
But, I'm not really sure about that. So my question is, would using a global be faster than using a get/set method call?
G-...
Is there a Windows standard way to do things such as "start fan", "decrease speed" or the like, from C/C++?
I have a suspicion it might be ACPI, but I am a frail mortal and cannot read that kind of documentation.
Edit: e.g. Windows 7 lets you select in your power plan options such as "passive cooling" (only when things get hot?) vs. "a...
I'm using select() on a Linux/ARM platform to see if a udp socket has received a packet. I'd like to know how much time was remaining in the select call if it returns before the timeout (having detected a packet).
Something along the lines of:
int wait_fd(int fd, int msec)
{
struct timeval tv;
fd_set rws;
tv.tv_sec = msec...