question
stringlengths 24
425
| answer
stringlengths 5
405
|
---|---|
Can we generate Control flow graph of the c program by Turbo C compiler?
I want to know that there is something given by the compiler to generate a CFG of a C program.
| Don't think Turbo C has this feature.
Though, modern IDEs have capabilities to draw Class Diagrams, but I personally haven't seen any IDEs drawing Flow diagrams.
Edit:
Hereis a list of tools that does what you want to achieve.
|
friends, I have a piece of code which can perform simple add, subtraction, multiplication, division, and formula with brackets.
Is there some kind of conversion tool for translating code from C to Smalltalk?
Or any other relatively easy way to achieve this?
Thanks in advance.
| This should be trivial to write withPetitParser
|
Hay All
Can we get the hard-disk number using php or C
Is there possible or not ?
This is not a problem just configuring.
| If you're using linux just read the file, /etc/fstab
I'm looking around for a windows equivalent.
|
Hay All
Can we get the hard-disk number using php or C
Is there possible or not ?
This is not a problem just configuring.
| If you're using linux just read the file, /etc/fstab
I'm looking around for a windows equivalent.
|
How would I convert an NSDate to a NSString, formatted with strftime specifiers?
| you could use strftime.
```
NSDate *date = [NSDate date];
time_t time = [date timeIntervalSince1970];
struct tm timeStruct;
localtime_r(&time, &timeStruct);
char buffer[80];
strftime(buffer, 80, "%d.%m.%Y %H:%M:%S", &timeStruct);
NSString *dateStr = [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding];
```
I hope it's correct.
|
Is it equivalent to a unsigned integer ?I'm able to use unsigned unknown_type_var = 3332934;
and print it successfully. This value is greater than a integer variable right ?
| unsigned is totally equivalent to unsigned int, just like long is equivalent to long int, etc.
|
I have a script that generates 2 code files (For example, src1.c, src2.c) according to another code file (say origin.h).I use a makefile to build them.Now, I want the script to be executed when src1.c OR src2.c is older that origin.h.
What is the best way to do that?
Thanks.
| Make src1.c and src2.c jointly dependent on origin.h:
```
src1.c src2.c : origin.h
build-sources
```
|
Refering tohttp://www.devx.com/tips/Tip/13291, it says that I can usememcpywith the size to copy determined bysizeof(), however, isn't the array pointing to a pointer?
Other than iterating through the array, how can I usememcpyto deep copy an array?
Thanks!
| In the linked exampleint weekly_hours[5][5];allocates space for 25 integers. There is no further indirection, so you can safely use memcpy to duplicate it's values.
|
How do I find what library files I need to include for the implementation of a particular c header if there is not library with the same name?
| I'd Google for the name of the header or the functions within it.
If you're on a Debian-based system you could also trydpkg -S <full header path>to tell you what package provided the header, then see what other files (in/usr/lib) that same package provides.
|
Is it equivalent to a unsigned integer ?I'm able to use unsigned unknown_type_var = 3332934;
and print it successfully. This value is greater than a integer variable right ?
| unsigned is totally equivalent to unsigned int, just like long is equivalent to long int, etc.
|
I have a script that generates 2 code files (For example, src1.c, src2.c) according to another code file (say origin.h).I use a makefile to build them.Now, I want the script to be executed when src1.c OR src2.c is older that origin.h.
What is the best way to do that?
Thanks.
| Make src1.c and src2.c jointly dependent on origin.h:
```
src1.c src2.c : origin.h
build-sources
```
|
Refering tohttp://www.devx.com/tips/Tip/13291, it says that I can usememcpywith the size to copy determined bysizeof(), however, isn't the array pointing to a pointer?
Other than iterating through the array, how can I usememcpyto deep copy an array?
Thanks!
| In the linked exampleint weekly_hours[5][5];allocates space for 25 integers. There is no further indirection, so you can safely use memcpy to duplicate it's values.
|
How do I find what library files I need to include for the implementation of a particular c header if there is not library with the same name?
| I'd Google for the name of the header or the functions within it.
If you're on a Debian-based system you could also trydpkg -S <full header path>to tell you what package provided the header, then see what other files (in/usr/lib) that same package provides.
|
without using multiplication or division operators.
You can use only add/substract operators.
| A pointless problem, but solvable with the properties of logarithms:
```
pow(a,b) = exp( b * log(a) )
= exp( exp(log(b) + log(log(a)) )
```
Take care to insure that your exponential and logarithm functions are using the same base.
Yes, I know how to use a sliderule. Learning that trick will change your perspective of logarithms.
|
How would I connect to char* strings to each other.
For example:
```
char* a="Heli";
char* b="copter";
```
How would I connect them to one char c which should be equal to "Helicopter" ?
| strncat
Or usestrings.
|
stack is increasing or decreasing using C program ?
| Right, in C usually variables in function scope are realized by means of a stack. But this model is not imposed by the C standard, a compiler could realize this any way it pleases. The word "stack" isn't even mentioned in the standard, and even less if it is in- or decreasing. You should never try to work with assumptions about that.
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:Enter Password in C
Ask user to enter Password without showing the input characters on console?
| You need to set the console to "no echo" mode. This depends on your particular OS. Here is an example of doing it for linux:http://www.cplusplus.com/forum/beginner/1988/page4.html#msg14522
|
I've a C code where I fetch headers for all mails in the inbox via imap issuing UID FETCH 1:* (FLAGS BODY[HEADER]) command. Due to special authentication requirements I cannot use a standard imap library like vmime or libetpan. I need to parse the mail header values in accordance with RFC 822. Do we have some library/function in C/C++ which will do the job ?
| Mimetic works great ! it also takes care of non-standard mail headers.
|
I have a static method in a cpp file (not in class) .
I want to use it globally without redeclaring it as extern .
In that case is it possible to use a global function pointer to this static method and
use this function pointer globally ??
| It is possible to do what you want, but why would you avoid using extern when it does exactly what you are trying to emulate through a much more convoluted (and unreadable) mechanism?
|
Is it possible to still use inet_ntoa() and not worry about Windows User Permissions? Do I need to put a try/catch block around inet_ntoa() to catch any possible problems if User Permissions prevent me from getting the IP address of an interface?
| inet_ntoadoesn't raise exceptions. It returnsNULLin case of an error.
It's hard to see how user permissions could come into this function since it is just an integer to string conversion.
|
I have a 16 bit fixed point processor and I want to do fixed point processing with it. I'm looking for the correct datatype to use for unsigned 16 bit ints..
My question is: what is the difference between auint16_tanduint_fast16_t? (These are included in thestdint.h.) Isuint_fast16_tbetter since it is faster??
Thanks!!
| uint16_tis an unsigned 16-bit integer.uint_fast16_tis the fastest available unsigned integer with at least 16 bits.
|
```
int solutions[92][81];
void add_solution(int board[81]) {
solutions[found_sltns++] = board;
}
```
Code sample attached, I get
error: incompatible types when
assigning to type ‘int[81]’ from type
‘int’
when compiling
Any clue?
| You can't copy array in this manner. You have to perform a element by element copy.
```
int i;
for(i=0;i<81;i++)
solutions[found_sltns][i] = board[i];
found_sltns++;
```
|
I've a C code where I fetch headers for all mails in the inbox via imap issuing UID FETCH 1:* (FLAGS BODY[HEADER]) command. Due to special authentication requirements I cannot use a standard imap library like vmime or libetpan. I need to parse the mail header values in accordance with RFC 822. Do we have some library/function in C/C++ which will do the job ?
| Mimetic works great ! it also takes care of non-standard mail headers.
|
I have a static method in a cpp file (not in class) .
I want to use it globally without redeclaring it as extern .
In that case is it possible to use a global function pointer to this static method and
use this function pointer globally ??
| It is possible to do what you want, but why would you avoid using extern when it does exactly what you are trying to emulate through a much more convoluted (and unreadable) mechanism?
|
Is it possible to still use inet_ntoa() and not worry about Windows User Permissions? Do I need to put a try/catch block around inet_ntoa() to catch any possible problems if User Permissions prevent me from getting the IP address of an interface?
| inet_ntoadoesn't raise exceptions. It returnsNULLin case of an error.
It's hard to see how user permissions could come into this function since it is just an integer to string conversion.
|
I have a 16 bit fixed point processor and I want to do fixed point processing with it. I'm looking for the correct datatype to use for unsigned 16 bit ints..
My question is: what is the difference between auint16_tanduint_fast16_t? (These are included in thestdint.h.) Isuint_fast16_tbetter since it is faster??
Thanks!!
| uint16_tis an unsigned 16-bit integer.uint_fast16_tis the fastest available unsigned integer with at least 16 bits.
|
As above, say I have a 3 dimensional array, a[][][], and I want to pass this to a function; how should I declare the function parameter?
| ```
void function1(int array[][3][4])
{
...use array here...
}
void function2(void)
{
int array[20][3][4];
...load array...
function1(array);
}
```
|
Is there any way I can synchronize the data(data sharing) between C and Java code with JNI using mutex or any other methods.
Please let me know if you have any documentation about the methods for data sharing.
| You can use any lock you prefer in C and make it available to Java via JNI.
You can do the reverse as well, calling a method in Java from C to use the lock.
I would do it natively in the framework which created the thread.
|
Consider printf:
```
int printf ( const char * format, ... );
```
What are the terms used to describe the...and the functions that use it? I've been calling it an ellipsis, but that's like calling&the "ampersand operator."
| Variable length parameter list
Edit:
Or, if describing the function itself:Variadic function
|
How could I simple initialize a multidimensional C-array with 0 elements like this:
```
int a[2][2] = { { 0, 0 }, {0, 0} }
```
| This should work:
```
int a[2][2] = {0};
```
EDITThis trick may work for silencing the warning:
```
int a[2][2] = {{0}};
```
|
How do I do a deep copy of a python object using the C API? I know I can use copy.deepcopy, but I'd prefer to use the C API if I can.
| The functionality ofcopy.deepcopy()iscompletely written in Python. I don't think they would have done this if there was a single C call to achieve the same thing, so my guess is you will have to callcopy.deepcopy().
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:How do I call unmanaged C/C++ code from a C# ASP.NET webpage
I have a dll file that is written in "C" language, i want to use it in C#. How can i do that?
| You can usePInvoke
Platform Invocation Services (PInvoke)
allows managed code to call unmanaged
functions that are implemented in a
DLL.
Hereis a great tutorial by the NAG (Numerical Algorithms Group) group
|
As above, say I have a 3 dimensional array, a[][][], and I want to pass this to a function; how should I declare the function parameter?
| ```
void function1(int array[][3][4])
{
...use array here...
}
void function2(void)
{
int array[20][3][4];
...load array...
function1(array);
}
```
|
Is there any way I can synchronize the data(data sharing) between C and Java code with JNI using mutex or any other methods.
Please let me know if you have any documentation about the methods for data sharing.
| You can use any lock you prefer in C and make it available to Java via JNI.
You can do the reverse as well, calling a method in Java from C to use the lock.
I would do it natively in the framework which created the thread.
|
Do you know a good example of nonlinear programming?, I have search over google, but any text just formulate and do not solve the problem, They mention lingo and even excel for solving it.
Could you please post an example and explain a little of if?
Thanks in advance
P.d
You know the idea is to see some results, and numbers, using C, java.
Thanks
| try these (java):
Example1
Example2
Example3
|
```
int *(*(*P)[2][2])(int,int);
```
P is a pointer to 2x2 array of pointers to a function with 2 type int parameters, that returns a int type pointer. Is this correct?
| cdeclis a great tool for figuring these kinds of problems out:
```
$ cdecl
Type `help' or `?' for help
cdecl> explain int *(*(*P)[2][2])(int,int);
declare P as pointer to array 2 of array 2 of pointer to function (int, int) returning pointer to int
```
So yes, you're correct.
|
Given atime_tas1291121400, how do I get the date of that day formatted as20101130?
| Usegmtime(3)orlocaltime(3)to convert it into astruct tm(Or, better, the reentrant versionsgmtime_rorlocaltime_r), and
then usestrftime(3)to turn it into a string. For example, if you
want the output in UTC:
```
struct tm tm;
char buf[9];
gmtime_r(&my_time_t, &tm);
strftime(buf, sizeof(buf), "%Y%m%d", tm);
printf("The date is: %s\n", buf);
```
|
I saw some C while loop with predicate as while(*ptr), and ptr is usually of char * type, how does this work? Does this mean "while()" will also accept values other than 1 or 0 as predicates?
| In C, any non-zero value is considered "true", sowhile (*ptr)will loop as long as*ptris non-zero.
|
Using Linux and glibc, when originating a TCP/IP connection (calling connect() on a socket), how can I choose explicitly from which of my IP local adresses I want to originate that connection, providing I have more than one interface (with different IPs) from where I can reach the remote host?
Is it possible to do so, or it is always up to the operating system IP stack to chose the route automatically?
| Bind to a specific address instead of0.0.0.0or::.
|
i need to get the terminal cursor position then set it, i already know how to set it using "move", that's in ncurses, any ideas?
| Have you triedgetyx()?
Or, if you prefer legacy curses functions,getcurx() and getcury()?
|
Given atime_tas1291121400, how do I get the date of that day formatted as20101130?
| Usegmtime(3)orlocaltime(3)to convert it into astruct tm(Or, better, the reentrant versionsgmtime_rorlocaltime_r), and
then usestrftime(3)to turn it into a string. For example, if you
want the output in UTC:
```
struct tm tm;
char buf[9];
gmtime_r(&my_time_t, &tm);
strftime(buf, sizeof(buf), "%Y%m%d", tm);
printf("The date is: %s\n", buf);
```
|
I saw some C while loop with predicate as while(*ptr), and ptr is usually of char * type, how does this work? Does this mean "while()" will also accept values other than 1 or 0 as predicates?
| In C, any non-zero value is considered "true", sowhile (*ptr)will loop as long as*ptris non-zero.
|
Using Linux and glibc, when originating a TCP/IP connection (calling connect() on a socket), how can I choose explicitly from which of my IP local adresses I want to originate that connection, providing I have more than one interface (with different IPs) from where I can reach the remote host?
Is it possible to do so, or it is always up to the operating system IP stack to chose the route automatically?
| Bind to a specific address instead of0.0.0.0or::.
|
i need to get the terminal cursor position then set it, i already know how to set it using "move", that's in ncurses, any ideas?
| Have you triedgetyx()?
Or, if you prefer legacy curses functions,getcurx() and getcury()?
|
```
void foo()
{
char *var = kmalloc(1, GFP_KERNEL);
return;
}
```
This code will cause kernel level memory leaks, what is the difference between this and user land memory leaks
This is a question from a interview today. I did bad about this question.Can anyone give any thoughts?
| Memory leaked in userspace is reclaimed at process termination, but memory leaked in kernel space cannot be reclaimed until the machine is rebooted.
|
When compiling this code with gcc
```
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
typedef struct _Nodo
{
unsigned int id_thread;
int id_mutex;
_Nodo *solicita;
_Nodo *asignado;
}Nodo;
```
I get:
```
libdrm.c:13: error: expected specifier-qualifier-list before ‘_Nodo’
```
Why?
| Try:struct _Nodo *solicita.
|
can anyone explain these lines to me:
```
int xyz( void )
{
extern void abc( void );
}
```
a function declaration within a function definition?
or am I missunderstanding something?
| Yes, your guess is correct. It's declaring the existence of the functionabc(), so it may be referenced withinxyz(). Note that theexternis unnecessary, as functions areexternby default.
|
In C/C++, what does the following mean?
```
for(;;){
...
}
```
| It's an infinite loop, equivalent towhile(true). When no termination condition is provided, the condition defaults to false (i.e., the loop will not terminate).
|
I'm fairly sure the set code should look like this:
```
function setPYR(float pitch, float yaw, float roll) {
glLoadIdentity();
glRotatef(pitch, 1, 0, 0);
glRotatef(yaw, 0, 1, 0);
glRotatef(roll, 0, 0, 1);
}
```
How can I get the pitch, yaw and roll from the current modelview matrix?
| Give a look atThe Matrix and Quaternions FAQ.
|
So I have my config file .vimrc that has this code which should save the file compile and run it when I press F3. This doesn't work.
```
map <F3> ^M:w^M:!gcc *.c -g; ./a.out^M
```
| Your keymapping worked for me (assuming you type^Mas e.g. Ctrl-V Ctrl-M).
If you have a makefile setup (and you probably should) you can just use:make.
You can set themakeprgoption if you use something other thanmake, e.g.cmakesconsantor something else.
|
Hi I created a server program that forks a new process after its accepts a socket connection.
There are several statically allocated global variables defined in the program. My question is are these static buffers allocated twice after the fork? Or does the fork only duplicate address space on the heap and the call stack?
| Theentireaddress space is duplicated, including all global variables and the program text.
|
Already read throughthis related question, but was looking for something a little more specific.
Is there a way to tell your compiler specifically how wide you want your enum to be?If so, how do you do it? I know how to specify it in C#; is it similarly done in C?Would it even be worth doing? When the enum value is passed to a function, will it be passed as anint-sized value regardless?
| I believe there is a flag if you are using GCC.
-fshort-enums
|
My string length is constant but actual data length will vary as like below,
```
" 1,54" // will be displayed as "- 1,54"
"123456789012,12" // will be dsiplayed as "- 123456789012,12"
```
| Wouldn't it be easiest to just put a '-' in the format string when you display the data?
```
printf("-%f", 1.54);
```
|
My string length is constant but actual data length will vary as like below,
```
" 1,54" // will be displayed as "- 1,54"
"123456789012,12" // will be dsiplayed as "- 123456789012,12"
```
| Wouldn't it be easiest to just put a '-' in the format string when you display the data?
```
printf("-%f", 1.54);
```
|
I want to generate 2 random numbers between 0 and 20
```
int one = rand() % 20;
```
it gives me 1 steady value i.e 1...
Am I missing something?
| You have to give a seed to the random number.
```
srand( time(NULL) );
int num1 = rand() % count;
int num2 = rand() % count;
```
Random number between 1 and 20
```
int num = rand() % 20 ;
if( num == 0 )
num += 2;
else if( num == 1 )
++num ;
```
|
I am a beginner of C. I run the C program, but the window closes too fast before I can see anything. How can I pause the window?
| you can put
```
getchar();
```
before the return from the main function. That will wait for a character input before exiting the program.
Alternatively you could run your program from a command line and the output would be visible.
|
Suggestions needed for best instrumentation tools for a C project. I actually like to know when control was transferred from a function to another function and therefore I want to do something like instrumenting printf commands at the end and start of each function.
| Thevalgrindtool has all sorts of hooks you can program that would let you watch this happen. In particular,thecallgrindtoolmight be appropriate here.
|
Given a unsigned char bitmapRep[8192], how to efficiently find out all "1" bits' positions? Thanks.
| What do you mean by "find"?
This may seem like a smart-ass answer, but I'm perfectly serious: you alreadyhavefound them. There's a perfect map describing exactly where all the 1 bits are found, and it has a bit set in the corresponding positions.
|
I need to print a variable which is a COLORREF.
| You might also want to break it up into the individual RGB components:
```
printf("R: %i, G: %i, B: %i", GetRValue(color), GetGValue(color), GetBValue(color));
```
this would give you something like:
R: 255, G: 150, B: 75
|
For my compiler tests, I need to generate this warning "Statement has no effect" in my test code. How can I do this?
Using VS cl.exe compiler
| ```
so ross$ cat > noeff.c
void f(void) {
1;
}
so ross$ cc -Wall -c noeff.c
noeff.c: In function ‘f’:
noeff.c:2: warning: statement with no effect
so ross$
```
|
Expanding myother question..
```
unsigned char* s_char = data + offset;
(*s_char) = size_t(((*s_char) & 0xf0)) | new_doff;
```
How to print s_char's bit representation?
| You'll need to manually print it using something like:
```
printf("%d%d%d%d%d%d%d%d", *s_char & 0x80, *s_char & 0x40, ..., *s_char & 0x01);
```
|
I have a C program that usessprintf_s. It works fine in Windows, but when I compile my code in Linux it gives this error:
```
sprintf_s was not declared in this scope.
```
Why does this happen and how can I fix it?
| It's not standard, you won't find such function on Linux.
Standard functionsnprintfshould have a similar semantics.
|
What's the quickest, easiest way to find the memory address of the first local variable in the activation record? (In C..)
Doesn't matter what we have declared already. Could be simple as char *s = 'Hello world!'
Thanks!
| You can't do that - the C standard doesn't even require that thereisa stack, let alone requiring a standard way to find out the order in which variables were put on it.
|
It seems that some autoconf projects use aconfigure.infile to generate aconfigurescript, and some useconfigure.ac.
What is the difference/advantage between using one or the other?
| Its just a matter of style. Historically autoconf files were namedconfigure.in. Nowconfigure.acis the preferred naming scheme. Its also discussed in thedocumentation.
|
Anyone please tell me where the main() function of the 'C' language returns its value?
| C'smainfunction returns an int... that int goes to the program which executed it (the parent process, if you will) as an exit status code.
Specifically, on most operating systems, a 0 exit code signifies a normal run (no real errors), and non-zero means there was a problem and the program had to exit abnormally.
|
It seems that some autoconf projects use aconfigure.infile to generate aconfigurescript, and some useconfigure.ac.
What is the difference/advantage between using one or the other?
| Its just a matter of style. Historically autoconf files were namedconfigure.in. Nowconfigure.acis the preferred naming scheme. Its also discussed in thedocumentation.
|
Anyone please tell me where the main() function of the 'C' language returns its value?
| C'smainfunction returns an int... that int goes to the program which executed it (the parent process, if you will) as an exit status code.
Specifically, on most operating systems, a 0 exit code signifies a normal run (no real errors), and non-zero means there was a problem and the program had to exit abnormally.
|
Is there an easy way, on *nix platforms(Linux specifically) to get the IP address of a hostname, while supplying a custom DNS server to use in place of the system's configured one? I want to access this information from a C program.
| You will need to use your own resolver, directly sending DNS packets, instead of relying on the system's resolver andgethostbyname. You would probably want to use a library, such asadns.
|
```
int x = 0;
x^=x || x++ || ++x;
```
and the answer for x at last is 3.
How to analysis this expression?
little confused about this.
Thanks a lot.
| This is undefined behaviour. The result could be anything. This is because there is nosequence pointbetween the++xand thex ^=, so there is no guarantee which will be "done" first.
|
```
file * fp = fopen()
file * fd = ????
```
I want to use*fdto write file which*fpopened before.
How can I do it?
Add some, the key of this question is use another pointer to do it. See, *fd is the different pointer. Wish i made this clear.
| ```
file* fd = fp;
```
If I understand you correctly, of course.
|
I have a program that executes various shell commands viasystem()and occasionally prints tocout. I want to redirect all output coming fromsystem()calls to a log file so they don't clutter up the normal output. Can I do this without having to append> logto all my system commands?
| Looks like you can usepopen
|
i want to do some modification and development for VLC. i download its source code, vlc-1.1.5. and it is written by C. so usually which development environment should i use, xcode or some others?
thx...
| I thought VLC was developed inQt. Do you see the class names starting with Q? In case it is developed in Qt,Qt CreatororKDevelopwould be a good choice of development environment.
|
im trying to read newline terminated strings using windows api and saw that the serialport class has a serialport.newline member. i want to know if it is possible to use the serialport class in c and how
| In (Microsoft) C, you'd need to callCreateFileto get a handle to the serial port, and_open_osfhandle(handle, _O_TEXT)to convert it to a file descriptor. You can get aFILE*from that file descriptor with_fdopen. After that,fscanfwill read lines.
|
```
error: expected ‘)’ before ‘[’ token
error line is - void display(ptr[i]);
```
this is the error which i get after compilation, what does it mean, i have written a simple program in C
| I can only imagine you are missing a ')' on the line above that line. But more source code would help in identifying the problem.
|
Is there any way to check the granularity of gettimeofday() function provided by POSIX?
| Instead ofgettimeofday(), consider usingclock_gettime()(specifying theCLOCK_REALTIMEclock). This is also POSIX, and supports aclock_getres()function to obtain the resolution.
|
Is there any way to check the granularity of gettimeofday() function provided by POSIX?
| Instead ofgettimeofday(), consider usingclock_gettime()(specifying theCLOCK_REALTIMEclock). This is also POSIX, and supports aclock_getres()function to obtain the resolution.
|
How do I set a fixed window size for a GTK+ app? I have:
```
gtk_window_set_default_size(GTK_WINDOW(mainWindow), 400, 300);
gtk_window_set_policy (GTK_WINDOW(mainWindow), FALSE, FALSE, FALSE);
```
but the window gets very small. There are no widgets yet.
| Usegtk_window_set_resizablefunction for this purpose
```
gtk_window_set_default_size(GTK_WINDOW(mainWindow), 400, 300);
gtk_window_set_resizable (GTK_WINDOW(mainWindow), FALSE);
```
|
As C does not have boolean types, how can I write a function like this in C:
```
bool checkNumber()
{
return false;
}
```
| Thebooltype is defined in the<stdbool.h>header, and is available under the name_Boolotherwise (assuming you're using a C99 compiler). If you don't have C99, you can always invent your own bool type like this:
```
typedef enum {false, true} bool;
```
|
As C does not have boolean types, how can I write a function like this in C:
```
bool checkNumber()
{
return false;
}
```
| Thebooltype is defined in the<stdbool.h>header, and is available under the name_Boolotherwise (assuming you're using a C99 compiler). If you don't have C99, you can always invent your own bool type like this:
```
typedef enum {false, true} bool;
```
|
As C does not have boolean types, how can I write a function like this in C:
```
bool checkNumber()
{
return false;
}
```
| Thebooltype is defined in the<stdbool.h>header, and is available under the name_Boolotherwise (assuming you're using a C99 compiler). If you don't have C99, you can always invent your own bool type like this:
```
typedef enum {false, true} bool;
```
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:C Analog To STL
Is there something like STL for C.
| You can have a look at theglib, which provides lots of interesting features
|
I need a good implementation of a (thread safe) cyclic buffer written in c.
Does anybody know where i can get it?
thanks!
| Have you looked atthiswikipedia record? They give an example, and have more external links.
As for thread-safe access just wrap the object with your own if needed, and throw a lock() / unlock() at it.
|
I want to copy folder A and paste to desktop.
I am currently using C++ so preferably an OO interface if available.
| On Windows (Win32), you could useSHFileOperation, eg:
```
SHFILEOPSTRUCT s = { 0 };
s.hwnd = m_hWnd;
s.wFunc = FO_COPY;
s.fFlags = FOF_SILENT;
s.pTo = "C:\\target folder\0";
s.pFrom = "C:\\source folder\\*\0";
SHFileOperation(&s);
```
|
There is a Ruby process and has a string var named "switch", and the "switch" will be updated by user. There are also 2 C daemon process, which need to access the "switch" in a loop and decide the logic in runtime, how to deal with this case ? thanks!
| A socket (or a common file) can be used as a pipe between them.
|
Given two events with integer start and end times, E1 = (s1, e1), E2 = (s2, e2), implement a quick boolean check to see if the events overlap.
I have the solution, but I'm curious to see what others come up with.
EDIT: OK, here's my solution:
```
e1 > s2 || (s1 > s2 && e2 < s1)
```
| bool overlap = (s1 <= e2) && (s2 <= e1)
|
I want to copy folder A and paste to desktop.
I am currently using C++ so preferably an OO interface if available.
| On Windows (Win32), you could useSHFileOperation, eg:
```
SHFILEOPSTRUCT s = { 0 };
s.hwnd = m_hWnd;
s.wFunc = FO_COPY;
s.fFlags = FOF_SILENT;
s.pTo = "C:\\target folder\0";
s.pFrom = "C:\\source folder\\*\0";
SHFileOperation(&s);
```
|
There is a Ruby process and has a string var named "switch", and the "switch" will be updated by user. There are also 2 C daemon process, which need to access the "switch" in a loop and decide the logic in runtime, how to deal with this case ? thanks!
| A socket (or a common file) can be used as a pipe between them.
|
Given two events with integer start and end times, E1 = (s1, e1), E2 = (s2, e2), implement a quick boolean check to see if the events overlap.
I have the solution, but I'm curious to see what others come up with.
EDIT: OK, here's my solution:
```
e1 > s2 || (s1 > s2 && e2 < s1)
```
| bool overlap = (s1 <= e2) && (s2 <= e1)
|
Is there a way to convert a hexdump e.g. aec4d2f3c6a4e70ea6cea074f65812d2a34b180cc92b817edcd867167e7a91c5beb942f0
to a string in c so that every two hexadecimal digits make a char? If so, what?
| Reads from stdin and prints to stdout:
```
int main()
{
int ch;
while(scanf("%2x", &ch) == 1)
putchar(ch);
}
```
I think you can modify it easily yourself for your specific source and destination requirements.
|
I am checking to make sure a float is not zero. It is impossible for the float to become negative. So is it faster to do thisfloat != 0.0for thisfloat > 0.0f?
Thanks.
Edit: Yes, I know this is micro-optimisation. But this is going to be called every time through my game loop, and I would like to know anyway.
| There is not likely to be a detectable difference in performance.
|
This question already has answers here:Closed11 years ago.
Possible Duplicate:How do you read C declarations?
I Don't understand the following:
```
int * (*(*p)[2][2])(int,int);
```
Can you help?
| For things like this trycdecl, decoded to;
```
declare p as pointer to array 2 of array 2 of pointer to function (int, int) returning pointer to int
```
|
```
#include<stdio.h>
double i;
int main()
{
(int)(float)(char) i;
printf("%d", sizeof((int)(float)(char)i));
return 0;
}
```
The above outputs 4 on a Micrsoft compiler. Why?
| sizeofis the size, in bytes, of the variable. In this case,iis being cast to anintwhich is 4 bytes.
These are the sizes of types on MS C++:http://msdn.microsoft.com/en-us/library/cc953fe1(v=vs.71).aspx
|
The following C/C++ code results in an Unused Entity Issue with XCode 4 (Clang LLVM).
```
void stringMethod(const char *string){
while(*string!=0){
*string++;
//...
}
}
```
Its on that line: *string++; so it seems like clang didnt realize that the pointer address is increased?
I don't get, how to adjust this code... Any ideas?
| Try to remove the dereferencing operator*, you don't need to dereference the pointer when you increase it.
|
```
int i; // A.
extern int i; // B.
```
I know A is a variable's definition. Namely, the compiler creates an object and assigns a block of memory to the variablei. But what is B? What's the difference between the definition and the declaration?
| It's a declaration. It says there is an integerithat will be defined elsewhere.
|
I want to include an IP packet in Socket programming. I have a readymade Ip packet which contains igmp packet. I don't want to design igmp protocol but want to use that packet to sent igmp query. By some how the Ip packet I have must be recognize as IP packet and not as TCP/UDP data.
| You have to usethe raw socketwithsendmsg. This needrootpermission.
|
The following C/C++ code results in an Unused Entity Issue with XCode 4 (Clang LLVM).
```
void stringMethod(const char *string){
while(*string!=0){
*string++;
//...
}
}
```
Its on that line: *string++; so it seems like clang didnt realize that the pointer address is increased?
I don't get, how to adjust this code... Any ideas?
| Try to remove the dereferencing operator*, you don't need to dereference the pointer when you increase it.
|
```
int i; // A.
extern int i; // B.
```
I know A is a variable's definition. Namely, the compiler creates an object and assigns a block of memory to the variablei. But what is B? What's the difference between the definition and the declaration?
| It's a declaration. It says there is an integerithat will be defined elsewhere.
|
I want to include an IP packet in Socket programming. I have a readymade Ip packet which contains igmp packet. I don't want to design igmp protocol but want to use that packet to sent igmp query. By some how the Ip packet I have must be recognize as IP packet and not as TCP/UDP data.
| You have to usethe raw socketwithsendmsg. This needrootpermission.
|
I see "printf" instruction in sample codes of c language for microcontroller particularly in 8051. Since microcontrollers has no fixed output display what is the use of the "printf" instruction?
| More likely than not, so you can attach a debugging console, either through an RS232 port, or as virtual output from an in-circuit emulator.
|
gcc 4.4.4 c89
Does any one know any sdp parses. That I can link to my application. Currently we are developing a SIP project. However, we need to parse the SDP for incoming/answering.
However, we don't have much time to implement. So just wondering if there are some simple ones out there they are easy and quick to work with.
Our application is written in c.
Many thanks for any advice,
| Check outFreeSDP. But it is distributed under GPL
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.