Currently, we are defining ourselves an extended log mechanism to print out the class name and the source line number of the log.
#define NCLog(s, ...) NSLog(@"<%@:%d> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
__LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])
For example, when I call NCLog(@"Hel...
char *substring(char *text, int position, int length)
{
int i, j=0;
char *temp ;
for(i=position-1; i<position+length-1; i++)
{
temp[j++] = text[i];
}
temp[j] = '\0';
return temp;
}
Hi What is the error in the following code.. I am trying to run this on Fedora Machine.. And its giving me a run-time error "Seg...
Under what circumstances will the "False" part of the following code be executed?
x = 20;
y = -30;
if (x > y) {
// True part
}
else {
// False part
}
NB: Language is C, compiler is gcc (although some other compilers may also do the same thing).
...
As far as I understand, GCC supports all of its C99 features in C++. But how is C99 strict aliasing handled in C++ code?
I know that casting with C casts between unrelated types is not strict-aliasing-safe and may generate incorrect code, but what about C++? Since strict aliasing is not part of C++ standard (is that correct?), GCC must ...
Hi, i want to implement a small routing table for my learning? I know it is implemented using radix/patricia tree in routers?
Can someone give me an idea on how to go about implementing the same?
The major issue i feel is storing IP ADDRESS.
For example : 10.1.1.0 network next hop 20.1.1.1
10.1.0.0 network next hop 40.1.1...
Here is the question
Is "missing semicolon" error really required? why not treat it as a warning?
Why I am asking this stupid question?
When I compile this code
int f = 1
int h=2;
the compiler intelligently tells me that where I am missing it. but to me its like - "If you know it, just treat it as if its there and go ahead. (Later ...
Is there a way to clone an existing struct with different member alignment in Visual C++?
Here is the background:
I use an 3rd-party library, which defines several structs. To fill up the structs, I pass the address of the struct instances to some functions. Unfortunately, the functions only returns unaligned buffer, so that data of so...
How to lock file in Windows so that this file can be opened/read/wrote only by one process?
I found out that file can be locked with CreateFile by giving 0 to dwShareMode flag. It works but only the returned handle can be used to work with file. But I want to be able to lock the file to other processes and at the same time to create mul...
Several questions on this website reveal pitfalls when mixing signed and unsigned types and most compilers seem to do a good job about generating warnings of this type. However, GCC doesn't seem to care when assigning a signed constant to an unsigned type! Consider the following program:
/* foo.c */
#include <stdio.h>
int main(void)
{...
I'd like to write a program which reads user input only from tty, instead of redirected stdin pipes, like passwd and ssh do. Is there any approach?
Many thanks
...
Is that possible? I've seen no method that would generate a plain old C vector or array. I have just NSNumber objects in my array which I need as C vector or array.
...
On a quite ancient UNIX (Apple A/UX 3.0.1 for 680x0 processors) using the built-in c compiler (cc), this issue arrises.
Here is the code I'm trying to compile:
#include <stdlib.h>
#include <stdio.h>
int main()
int argc;
char **argv;
{
if (argc > 1)
puts(argv[1]);
return (EXIT_SUCCESS);
}
And here is the o...
Well, rand_r function is supposed to be a thread safe function. However, by its implementation, I cannot believe it could make itself not change by other threads.
Suppose that two threads will invoke rand_r in the same time with the same variable seed.
So read-write race will occur.
The code rand_r implemented by glibc is listed below. A...
Hi all,
I want TCP/IP based socket server application or code for Linux, which performs a very simple operation: reads xml string from one of the connected socket clients and forwards it to all socket clients which are connected to it.
I have such client server application developed in cocoa, but according to my requirements now I need...
I have some project where I have a single producer thread which writes events into a buffer, and an additional single consumer thread which takes events from the buffer. My goal is to optimize this thing for a single dual-core machine to achieve maximum throughput.
Currently, I am using some simple lock-free ring buffer (lock-free is po...
There's a similar question, I know, but it confused me, so I thought it easier to ask in my way.
So I have an array of values, positive and negative. The higher they are, the more probability they have of being chosen.
I'm having trouble actually figuring out how to assign the probabilities and then randomly choose one. I'm guessing the...
How to write a kernel module that creates a directory in /proc named mymod and a file in it name is mymodfile. This file should accept a number ranged from 1 to 3 when written into it and return the following messages when read based on the number already written into it:
• 1: Current system time (in microseconds precision)
• 2: System ...
I was just wondering if there is an XOR logical operator in C (something like && for AND but for XOR). I know I can split an XOR into ANDs, NOTs and ORs but a simple XOR would be much better. Then it occurred to me that if I use the normal XOR bitwise operator between two conditions, it might just work. And for my tests it did.
Consider...
I have a large tree structure on which several threads are working at the same time. Ideally, I would like to have an individual mutex lock for each cell.
I looked at the definition of pthread_mutex_t in bits/pthreadtypes.h and it is fairly short, so the memory usage should not be an issue in my case.
However, is there any performanc...
How to find the size of an integer array in C.
Any method available without traversing the whole array once, to find out the size of the array..
Thankss..
...