question stringlengths 25 894 | answer stringlengths 4 863 |
|---|---|
I'm trying to reduce the size of an executable (using MINGW/GCC) by finding all large statically declared arrays. Is there a way to dump the list of data symbols along with their aggregate sizes?? I've looked at man pages for nm and objdump but dont see anything useful so far.
Thx.
|
Use thenmutility fromGNU binutilswith the--print-sizeoption (abbreviated-S). For example, to find the 20 largest symbols in an object file, do this:
```
nm --print-size --size-sort objfile.o | tail -20
```
|
```
#define INIT_MACRO create(); some(); enviroment();
...
void function(){
INIT_MACRO
extra_indented();
normal_indented();
}
```
how do i make emacs deal correctly with the above situation when it is requested to automatically indent?
EDIT the only solution i see is to tell emacs to treat lines containing o... |
This works:
```
#define INIT_MACRO do { create(); some(); enviroment(); } while (0)
...
void function(){
INIT_MACRO;
extra_indented();
normal_indented();
}
```
It is usually better to use this trick to avoid problems when you use:
```
if (...)
MACRO();
else
...
```
and a semicolon on each line is easier ... |
How can I convert 1.bmp 2.bmp ... n.bmp (each 24 bpp) into a single mng or apng file (with animation) in bash/cpp?
|
This program can create APNG from TGA/PNG sequences:
http://sourceforge.net/projects/apngasm/files/
|
is there any extension of valgrind, that can be used in the command window, that would help me know the time, in seconds, spent in each function in my C code?
thanks =)
|
For machine instruction profiling use valgrind'scallgrind(also,cachegrindcan do cache and branch prediction profiling which is quite nice).
For time measurements usegoogle's cpu profiler, it gives way better results than gprof. You can set sampling frequency and it can show the output as a nice annotated call graph.... |
I have a struct A that is defined as follows:
```
typedef struct A
{
CvRect B; // rect
int C;
double D;
}
A;
```
...
In my main program, I grab one item of a sequence of items:
```
A *r = (A*) cvGetSeqElem(X, i);
```
Whenever I try to access rect, I get one of the following errors:
```
if (r.rect.wi... |
ris a pointer to`struct A, which contains a (non-pointer) memberB(supposedlyrect?) to aCvRect. So you have to writer->rect.width
|
There is another thread explaining the way to get multiple values using scanf(). I tried that, however, I got correct value for the first variable and junk values for the remaining two variables. When I used separate scanf statements, it worked fine.
I am using RH Linux 5.
Kernel version - 2.6.18-238. 4.1.2
e.g. if I... |
You don't say what types the three variables are. They have to beint.
The following code works as expected on my computer:
```
#include <stdio.h>
int main()
{
int n, p1, p2;
scanf("%d %d %d", &n, &p1, &p2);
printf("%d %d %d\n", n, p1, p2);
return 0;
}
```
Here is the output:
```
$ gcc x.c
$ ./a.out
10 3 ... |
Are there any libraries available by default in the Android NDK? If not, can I use any c++/c library, as long as I include it myself?
In particular, I need compression, encryption, regex and sqlite. I was thinking of usingzlib,crypto++,sqlite(duh!) andboost, but can use anything else if it is already available.
Also... |
SQLite is available on Android via abstracteddatabase accessin Java. The .soitself is private. You can of course compile your own SQLite library if you require modifications, but in general you should access it from Java. I have done this for encryption purposes.zlibis available to the NDKcrypto++could of course be c... |
I am implementing a program in C (also in C++) to sort files using threads, I need to implement a GUI in C++ or C to select the file to sort, without indicating the path through input standard (a equivalent of JFileChooser in Java). What tutorials do you recommend? I was reading about Qt but I'm not very familiar with... |
Very simple with QT:
```
void openFile()
{
QFileDialog::getOpenFileName( this, tr("Open Document"), QDir::currentPath(), tr("Document files (*.doc *.rtf);;All files (*.*)"), 0, QFileDialog::DontUseNativeDialog );
QString filename = QFileDialog::getOpenFileName(
this,
tr("Open Document"), ... |
I am trying to write a small music manager in Linux using C++. I am currently using TagLib to read the media's metadata. However, as far as I know, TagLib does not support reading tags (title, artist, etc...) from a video. Therefore, I just want to ask you guys if there is any other library I can use to read the tags ... |
MediaInfolibrary
|
Is it possible to pass variable type as part of a function parameter, e.g.:
```
void foo(varType type)
{
// Cast to global static
unsigned char bar;
bar = ((type *)(&static_array))->member;
}
```
I remember it has something to do with GCC'stypeofand using macros?
|
You could make an enum for all different types possible, and use a switch to make the dereferencing:
```
typedef enum {
CHAR,
INT,
FLOAT,
DOUBLE
} TYPE;
void foo(TYPE t, void* x){
switch(t){
case CHAR:
(char*)x;
break;
case INT:
(int*)x;
... |
I was wondering if anyone knew of a way that I could feed an image file to a Python, C or Java program and get back the coordinates of where a specific string appears on the image?
|
What you're talking about is calledOptical Character Recognition, or OCR.
OCR isn't easy to implement from scratch, but there are libraries out there.OpenCV can be used for OCR.
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:Getting terminal width in C?
On Linux and OS X, my shell reports $COLUMNS has the width of the terminal window -- and resizing the window will adjust this shell variable.
But in my C/C++ program, getenv("COLUMNS") doesn't seem to find the... |
Perhaps something like this:
```
#include <sys/ioctl.h>
#include <stdio.h>
int main()
{
struct winsize w;
ioctl(0, TIOCGWINSZ, &w);
printf("lines %d\n", w.ws_row);
printf("columns %d\n", w.ws_col);
return 0;
}
```
Taken straight from:Getting terminal width in C?
|
I would like to split one array of char containing two "strings "separated by '|' into two arays of char.
Here is my sample code.
```
void splitChar(const char *text, char *text1, char *text2)
{
for (;*text!='\0' && *text != '|';) *text1++ = *text++;
*text1 = '\0';
for (;*++text!='\0';) *text2++ = *text;
... |
If you wan to write it in C++, use the STL
```
string s = "monday|tuesday";
int pos = s.find('|');
if(pos == string::npos)
return 1;
string part1 = s.substr(0, pos);
string part2 = s.substr(pos+1, s.size() - pos);
```
|
Following piece of my code does not print the value in visual studio.
```
int main() {
intptr_t P = 10;
printf("test value is %zd",P);
return 0;
}
```
OUTPUT:
```
test value is zd
```
I expect the the above code print
```
test value is 10
```
i am using intptr_t instead of integer so as to make the ... |
Thezprefix isn't defined in Microsoft's version ofprintf. I think theIprefix might work. Seehttp://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx
|
Sorry for my dumb question, but are wndproc and hooks in the main thread (when called)?
If they are does it mean I can not use them for build buffer for keyboard input?
|
Your window procedure (and any subclassed window procedures, hooks, etc) run in the thread which calledCreateWindow(it's a requirement for that same thread to later process the message queue, window procedures actually run when your main message dispatch loop callsDispatchMessage).
Not sure what you mean by "build bu... |
I'm trying to force my C program to line buffer (stdout is going to be captured by a java program), but it always seems to fully buffer instead. Here is some sample code:
```
#include <stdio.h>
#include <stdlib.h>
int main(){
char c;
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
printf("Hello world\n");
c ... |
According tothis Microsoft documentation:
_IOLBF:
For some systems, this provides line buffering. However, for Win32, the behavior is the same as _IOFBF - Full Buffering.
|
ISHELL_BrowseURLreturns AEE_EBADCLASS when callled with a URL. (Such ashttp://google.com/)
The "po" (IShell*) argument is as far as we know OK. Do you have any advice regarding this? Close applet with the same class works, for instance.
|
On theHTC Smart(Same asHTC F3188or Dopod F3188), the standard browser can not be called.
Instead, call the HTC browser with id 0x0108d987:
int ret = ISHELL_StartAppletArgs(pMe->applet.m_pIShell, 0x0108d987,
"http://developer.att.com");
|
Is it possible to pass variable type as part of a function parameter, e.g.:
```
void foo(varType type)
{
// Cast to global static
unsigned char bar;
bar = ((type *)(&static_array))->member;
}
```
I remember it has something to do with GCC'stypeofand using macros?
|
You could make an enum for all different types possible, and use a switch to make the dereferencing:
```
typedef enum {
CHAR,
INT,
FLOAT,
DOUBLE
} TYPE;
void foo(TYPE t, void* x){
switch(t){
case CHAR:
(char*)x;
break;
case INT:
(int*)x;
... |
I was wondering if anyone knew of a way that I could feed an image file to a Python, C or Java program and get back the coordinates of where a specific string appears on the image?
|
What you're talking about is calledOptical Character Recognition, or OCR.
OCR isn't easy to implement from scratch, but there are libraries out there.OpenCV can be used for OCR.
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:Getting terminal width in C?
On Linux and OS X, my shell reports $COLUMNS has the width of the terminal window -- and resizing the window will adjust this shell variable.
But in my C/C++ program, getenv("COLUMNS") doesn't seem to find the... |
Perhaps something like this:
```
#include <sys/ioctl.h>
#include <stdio.h>
int main()
{
struct winsize w;
ioctl(0, TIOCGWINSZ, &w);
printf("lines %d\n", w.ws_row);
printf("columns %d\n", w.ws_col);
return 0;
}
```
Taken straight from:Getting terminal width in C?
|
I would like to split one array of char containing two "strings "separated by '|' into two arays of char.
Here is my sample code.
```
void splitChar(const char *text, char *text1, char *text2)
{
for (;*text!='\0' && *text != '|';) *text1++ = *text++;
*text1 = '\0';
for (;*++text!='\0';) *text2++ = *text;
... |
If you wan to write it in C++, use the STL
```
string s = "monday|tuesday";
int pos = s.find('|');
if(pos == string::npos)
return 1;
string part1 = s.substr(0, pos);
string part2 = s.substr(pos+1, s.size() - pos);
```
|
Following piece of my code does not print the value in visual studio.
```
int main() {
intptr_t P = 10;
printf("test value is %zd",P);
return 0;
}
```
OUTPUT:
```
test value is zd
```
I expect the the above code print
```
test value is 10
```
i am using intptr_t instead of integer so as to make the ... |
Thezprefix isn't defined in Microsoft's version ofprintf. I think theIprefix might work. Seehttp://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx
|
Sorry for my dumb question, but are wndproc and hooks in the main thread (when called)?
If they are does it mean I can not use them for build buffer for keyboard input?
|
Your window procedure (and any subclassed window procedures, hooks, etc) run in the thread which calledCreateWindow(it's a requirement for that same thread to later process the message queue, window procedures actually run when your main message dispatch loop callsDispatchMessage).
Not sure what you mean by "build bu... |
I'm trying to force my C program to line buffer (stdout is going to be captured by a java program), but it always seems to fully buffer instead. Here is some sample code:
```
#include <stdio.h>
#include <stdlib.h>
int main(){
char c;
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
printf("Hello world\n");
c ... |
According tothis Microsoft documentation:
_IOLBF:
For some systems, this provides line buffering. However, for Win32, the behavior is the same as _IOFBF - Full Buffering.
|
ISHELL_BrowseURLreturns AEE_EBADCLASS when callled with a URL. (Such ashttp://google.com/)
The "po" (IShell*) argument is as far as we know OK. Do you have any advice regarding this? Close applet with the same class works, for instance.
|
On theHTC Smart(Same asHTC F3188or Dopod F3188), the standard browser can not be called.
Instead, call the HTC browser with id 0x0108d987:
int ret = ISHELL_StartAppletArgs(pMe->applet.m_pIShell, 0x0108d987,
"http://developer.att.com");
|
for a while I have been using gprof to profile my C code but it is very very unstable, on every run it is giving me a different simulation time as well as %.
I have decided to switch to valgrind, I am profiling using the valgrind, however I want to display the data and get similar results to gprof. In gprof I got the ... |
So if you want to use bare data, why are you looking at the gui? Start from the lower level, the cachegrind itself.http://valgrind.org/docs/manual/cg-manual.html
|
Has anyone usedccccwith pure C code?
I tried it and it seems to handle all the files as one module, which means that most of the counters are useless (e.g. there is no fan-in or fan-out since there is just one module).
Can I somehow tell it to do this comparison on a file-by-file basis (i.e. each file is one module)... |
Seems a little bit outdated. I usually usesloccountwith good results.
|
I wrote the following code for string concatnation using pointers in C
```
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void strCat(char *str1,char *str2);
int main(void)
{
char str1[] = "Rohit";
char str2[] = "Kumar";
strCat(str1,str2);
return 0;
}
void strCat(char *str1,char *str2)
{
int i;
char *sta... |
Well, first of allstr1isn't long enough to fit both strings.
Here
```
while(*str2 != '\0')
*str1++ = *str2++; /* You are overstepping str1 -> undefined behavior */
```
There are other problems with the code. Perhaps you should try thestring.hstrcatinstead ?
|
I need to check the value of the least significant bit (LSB) and most significant bit (MSB) of an integer in C/C++. How would I do this?
|
```
//int value;
int LSB = value & 1;
```
Alternatively(which is not theoretically portable, but practically it is - see Steve's comment)
```
//int value;
int LSB = value % 2;
```
Details:The second formula is simpler. The % operator is the remainder operator. A number's LSB is 1 iff it is an odd number and 0 other... |
The following code
```
char buffer[BSIZE];
...
if(buffer[0]==0xef)
...
```
Gives the compiler warning "comparison is always false due to limited range of data type".
The warning goes away when I change the check to
```
if(buffer[0]==0xffffffef)
```
This feels very counterintuitive. What is the correct way to check... |
What's wrong with:
```
if (buffer[0] == '\xef')
```
?
|
When you are printing a tab character to the standard output usingprintfin C, it outputs some space which is apparently 4 characters in length.
```
printf("\t");
```
Is there a way by which I can control the tab width in the above case?
|
That's something controlled by your terminal, not byprintf.
printfsimply sends a\tto the output stream (which can be a tty, a file, etc.). It doesn't send a number of spaces.
|
I am not sure if I was dreaming or not because I can not find this function anywhere I look. The function calls for 2 strings to concat, then would return the pointer to a newly allocated memory block with the 2 strings fused.
Does anyone know of such a function?
|
I am not aware of anything like that in the C standard; POSIX C containsstrdupwhich returns a newly allocated copy of the provided string, but that's not what you are asking.
Still, you can easily build it by yourself:
```
char * strcat_alloc(const char * first, const char * second)
{
size_t s1=strlen(first), s2... |
Suppose:
```
6 char arr[] = "ABC";
7
8 char *ptr = &arr;
9 char *ptr2 = &ptr;
```
Usingptr2, how can i access elements ofc?
I would have thought the following would work, but ... it does not.
**ptr2[1]
|
You currently don't have a pointer-to-a-pointer.
Your code should be:
```
char c[] = "ABC";
char *ptr = c; // Note no &
char **ptr2 = &ptr; // Note **, not *. This is now a pointer-to-pointer
```
Then to access, you want this:
```
(*ptr2)[1]
```
|
how we can see the contents such as mysql_query() functions ?
How to write similar function with php?
|
To see the source of the PHP function, you would have todownload the sourceand look at the files and folders in the "ext" folder. PHP is written in C. You could write your own extensions in C and compile them in to PHP.
You can write your ownPHP function, in PHP, like this:
```
function name_of_your_function($parame... |
Does C sign extend constants or zero extend them?
For example:
```
int a = 123 & 0x3
```
is the 0x3 zero extend or sign extended?
Also in general, what things are zero extended in C and what are sign extended?
Thanks!
|
The C standard does not mandate whether the implementation uses 2's complement, 1's complement, or something else. So the representation of negative values is not mandated either.
However, in your particular case,0x3is a positive value, so sign-extension and zero-extension are the same thing!
|
How does the following piece of code work, in other words what is the algorithm of the C preprocessor? Does this work on all compilers?
```
#include <stdio.h>
#define b a
#define a 170
int main() {
printf("%i", b);
return 0;
}
```
|
The preprocessor just replacesbwithawherever it finds it in the program and then replacesawith170It is just plain textual replacement.
Workson gcc.
|
According to c99 standard, we can write the following code and it's totally legal
```
int x;
scanf("%d",&x);
int ar[x];
```
My question is, if I can allocate an array like this, why would I ever need malloc to allocate variable size arrays again?
Also, could you please explain how does the variable length arrays al... |
Two reasons spring to my mind:
Arrays that live beyond this stack frame.Arrays that are bigger than the stack.
|
If I use ntohl() on an integer which is already in host byte order will that cause any problems?
If not, how does the ntohl() function know its argument is already in host byte order?
|
Your question doesn't make any sense. Forntohlnothing is high-order or low-order.
If the endianness of the system is the same as network order, it will do nothingOtherwise it will swap stuff around
|
Is there a way to have one raw input buffer per device?
So I would like to have a buffer for mouse and another one for keyboard.
Is it possible?
|
Yes, trySetWindowsHookEx. You will have to convert WM_KEY* messages to WM_CHAR yourself, though.
|
I need to have atomic variables in my program. Previously I was usingstd::atomic<int>, but the platform in which I'm working now does not have a g++ compiler that supports C++0x. I usedvolatile intand it seems to be working, as I haven't experienced a race condition yet in the multicore system I'm testing it on.
My q... |
No.volatilehas nothing to do with multithreading. It doesn't enforce a memory barrier (although some compilers might choose to add thatanyway), and it makes no guarantees about read/write reordering with respect to non-volatile objects.
volatilewas added to support writing to memory-mapped hardware I/O registers, and... |
This question already has answers here:Closed12 years ago.
Possible Duplicates:C/C++ pragma in define macroConditional “pragma omp”
How can I use an OpenMP pragmas inside a macro definition? E.g.
```
#define A() { \
...a lot of code... \
#pragma omp for \
for(..) \
..do_for.. \
...anot... |
As it was answered hereConditional "pragma omp"
C99 has the_Pragmakeyword that allows you to place what otherwise would be#pragmainside macros. Something like
```
#define OMP_PARA_INTERNAL _Pragma("omp parallel for")
```
So,
```
#define OMP_PARA_FOR _Pragma("omp for")
#define A() { \
...a lot of code... \
OMP_PA... |
```
#include < stdio.h >
int main() {
char *s;
s=call();
printf(s);
}
char* call() {
return("hello");
}
```
Why these code not working. It's generating an error. How do I make it work?
|
Two things:
You can't put spaces inside the angle brackets when including a system header (e.g.#include <stdio.h>You need a prototype forcall()
|
I want to exclude some functions from the output generated by gprof. In other words, I do not want them to be included when calculating percentage time spent by each function during execution. I read at one place-Eoption can be used.
However I'm usinggprof -E function_to_be_exluded my_program_name, but nothing happen... |
Exactly, gprof -e -E are deprecated and superseded by usage of newer relevant options that have argument - symspecs. So try using:
```
gprof --no-time=symspec
The -n option causes "gprof", in its call graph analysis, not to propagate times for
symbols matching symspec.
e.g.
gprof --no-time=name_of_function_you_do... |
I came across a naming problem while working with the xlib library:
I'm using a struct which has a member called "class". I assume this library is mostly used in plain C programs. So there's no problem.
But I'm programming in C++ and here the name "class" is a keyword and cannot be used to denote variables. So, if I... |
Given that I cannot change the struct itself, how can I access this struct member despite the naming conflict?
Maybe you can rename it using a #define, something like
```
#define class xclass
#include "header.h"
#undef class
// ...
myvariable = mystruct->xclass;
```
|
Is it possible to have a function or macro to return variable type? I need to implement something like a conditional typedef. Example:
```
(var_type) foo (char a)
{
if (a == 1)
return char;
else
return int;
}
```
Such that I could :
```
foo(1) variable;
```
Note:... |
You can't do that. You could allocate your object on the heap and return avoid *to it. Or perhaps you could use a union.
|
I am in a project where I need to do some book-keeping i.e to indicate whether a particular file has been accessed by a program A. I plan to store this information in the inode as using other additional datastructure would be inefficient.
I plan to reuse the field i_mode in the inode datastructure. Any suggestions.... |
The file system looks after the inode; it won't even let super-user modify the inode directly (though root can always access the unmounted (block or character) device to change it).
Unless you write code to modify the file system - a kernel module - you will not be able to do as you wish. Find another way to do it.
|
C and C++ by themselves can't actuallydoanything, they need the libraries to work. So how were the libraries created? Assembly language?
|
C and C++ libraries are almost universally written in C and C++, as are C and C++ compilers. In fact, many compilers are even used to compile themselves!
How is this possible? Well, obviously the first C compiler couldn't have been initially developed in C. However, once a C compiler exists, then it can be used to co... |
By default, GDB always prints/displays all variables / arguments in base 10.
Is there any way to ask GDB to always use base 16 while printing anything (and turn back to default settings when I don't need that)?
I know that it can be printed by supplying the/xargument to print/display, but I don't want to do it every... |
set output-radix 16(andset output-radix 10to switch it back).
|
According toISO 8601, time can be specified in different formats.
My program does not know which exact ISO 8601 format will be specified.
In this case, how can I convert it to time_t?
strptimerequires you to specify format (which I do not know before hand in my case).
Ultimate goal: is to compare 2 time_t timestam... |
If you are on a UNIX like machine, trygetdate. The interface is funky but works pretty good.
Which formats are recognized is
controlled by the file named by the
environment variable DATEMSK. This
file should contain lines of valid
format strings which could be passed
to strptime.
|
According to section 4.9.6.1 of theC89 draft, %d is a character that specifies the type ofconversionto be applied.
The wordconversionimplies, in my opinion, thatprintf("%d", 1.0)is defined.
Please confirm or refute this.
|
The conversion is the conversion of a language value to a lexical representation of that value.
Your theory is wrong; behavior is undefined. The spec says (7.19.6.1p8 and 9, using C99 TC2):
Theintargument is converted to signed decimal in the style [−]dddd.
And
If any argument is not the correct type for the corre... |
This question already has answers here:Closed12 years ago.
Possible Duplicate:Should I use char** argv or char* argv[] in C?
What is the difference between usingchar **argvandchar *argv[]for the second parameter to a c program. Does it affect the way the strings are passed? Thanks :-)
|
There is absolutely no difference. At all.
in C
```
void f(int*);
```
and
```
void f(int[]);
```
and
```
void f(int[42]);
```
are three completely identical declarations.
|
How can I authenticate to a web service hosted in IIS that is secured with Integrated Windows Authentication?
Do I use HTTP headers to add username and pwd?
I am trying to call this web service from UNIX in C.
|
I'm rather a newbie to IIS myself, and I'm just starting to dance around this topic, but I saw your note and thought it was crazy that no one has answered in so long!
I believe that the typical way that windows authenticates is Kerberos. You may have to go through some gyrations to get the Windows Kerberos server to... |
I have a question regarding the following code:
```
while((c = getc(pFile)) != EOF)
{
if(c != '\n')
{
input[index] = (char)c;
index++;
} else
{
input[index] = '\0';
index = 0;
}
}
```
In Windows, this c = getc line reads '\n' (code 10) twice. For example, I... |
Is the file physically the same, i.e. bit-by-bit, on the two platforms? That's asking for trouble, since the encoding for line ending differs.
|
is it possible to do an atomic write on the block level?as an example consider the following:
```
__global__ kernel (int atomic)
{
atomic+=blockid.x; //should be atomic for each block
}
```
|
You can do some atomic operations in CUDA. See Apendix B.11 Atomic Functions in the CUDA Programming Guide. i.e.:
```
__global__ void kernel (int *result)
{
atomicAdd(result, blockIdx.x); //
}
```
You can also exchange the value of a variable
```
__global__ void kernel (int *result)
{
atomicExch(result, bl... |
This question already has answers here:Closed12 years ago.
Possible Duplicate:What is ultimately a time_t typedef to?
In /usr/include/time.h time_t is defined astypedef __time_t time_t. What does this mean exactly? Is the type of time_t compiler specific? I have heard it is by default alongvalue.
|
The Standardsays:
7.23.1The types declared are [...] time_t [...] which are arithmetic types capable of representing times
You just need to retain that it is an arithmetic type: you can perform arithmetic with values oftime_ttype.
|
```
#include < stdio.h >
#include < string.h >
int main()
{
unsigned char a;
FILE *P;
P=fopen("mola.txt","r");
while((a=getc(P))!=EOF)
printf("%c",a);
}
```
Whats wrong with these code? When I compile it gives warning "comparison is always true due to limited range of data type." What does that warning mean?... |
You are storing the result ofgetcin achar. It should be anint. There's also aC FAQon it. Also you should check the return value of thefopen.
```
P=fopen("mola.txt","r");
if (NULL == P) {
perror("fopen"):
}
```
Also thewhilelooks fishy. Try indenting ?
```
while((a=getc(P)) != EOF)
printf("%c",a);
```
|
I have made a dll in Microsoft Visual Studio 2005. Then i am trying to use it in other project on the other computer in CodeBlocks IDE. Project is built, but when it use functions from dll i got an error: "The program can't start because MSVCR80D.dll is missing from your computer. Try reinstall the program to fix this... |
You're trying to run a debug version, which is linked to the debug version of the CRT. The latter is only available where VS has been installed. You should use the release version of your project on other machines (or manually copy all the dependent debug DLLs, which is not legal according to the license...).
|
Closed. This question needs to be morefocused. It is not currently accepting answers.Want to improve this question?Update the question so it focuses on one problem only byediting this post.Closed9 years ago.Improve this question
There some machines:
client C1, server : master, s1, s2
C1 connect to master and do the ... |
Request the GSSAPI toencryptyour communication. I use this with SASL and Active Directory. All traffic is securely wrapped.
|
popenstores o/p of the specified command into a file. How can I get similar functionality but o/p into a variable (i.e. in a char*) ?
|
No,popen()does not store output into a file. It specifies astream, whichmightrepresent to a file on disk but which might also be at e.g. a pipe or socket. Streams are more abstract than files.
To have a pipe, you would open the pipe using e.g.pipe()and then callfdopen()on the proper end of the resulting pipe.
|
```
#include < stdio.h >
int main() {
char *s;
s=call();
printf(s);
}
char* call() {
return("hello");
}
```
Why these code not working. It's generating an error. How do I make it work?
|
Two things:
You can't put spaces inside the angle brackets when including a system header (e.g.#include <stdio.h>You need a prototype forcall()
|
I want to exclude some functions from the output generated by gprof. In other words, I do not want them to be included when calculating percentage time spent by each function during execution. I read at one place-Eoption can be used.
However I'm usinggprof -E function_to_be_exluded my_program_name, but nothing happen... |
Exactly, gprof -e -E are deprecated and superseded by usage of newer relevant options that have argument - symspecs. So try using:
```
gprof --no-time=symspec
The -n option causes "gprof", in its call graph analysis, not to propagate times for
symbols matching symspec.
e.g.
gprof --no-time=name_of_function_you_do... |
I came across a naming problem while working with the xlib library:
I'm using a struct which has a member called "class". I assume this library is mostly used in plain C programs. So there's no problem.
But I'm programming in C++ and here the name "class" is a keyword and cannot be used to denote variables. So, if I... |
Given that I cannot change the struct itself, how can I access this struct member despite the naming conflict?
Maybe you can rename it using a #define, something like
```
#define class xclass
#include "header.h"
#undef class
// ...
myvariable = mystruct->xclass;
```
|
Is it possible to have a function or macro to return variable type? I need to implement something like a conditional typedef. Example:
```
(var_type) foo (char a)
{
if (a == 1)
return char;
else
return int;
}
```
Such that I could :
```
foo(1) variable;
```
Note:... |
You can't do that. You could allocate your object on the heap and return avoid *to it. Or perhaps you could use a union.
|
I am in a project where I need to do some book-keeping i.e to indicate whether a particular file has been accessed by a program A. I plan to store this information in the inode as using other additional datastructure would be inefficient.
I plan to reuse the field i_mode in the inode datastructure. Any suggestions.... |
The file system looks after the inode; it won't even let super-user modify the inode directly (though root can always access the unmounted (block or character) device to change it).
Unless you write code to modify the file system - a kernel module - you will not be able to do as you wish. Find another way to do it.
|
C and C++ by themselves can't actuallydoanything, they need the libraries to work. So how were the libraries created? Assembly language?
|
C and C++ libraries are almost universally written in C and C++, as are C and C++ compilers. In fact, many compilers are even used to compile themselves!
How is this possible? Well, obviously the first C compiler couldn't have been initially developed in C. However, once a C compiler exists, then it can be used to co... |
By default, GDB always prints/displays all variables / arguments in base 10.
Is there any way to ask GDB to always use base 16 while printing anything (and turn back to default settings when I don't need that)?
I know that it can be printed by supplying the/xargument to print/display, but I don't want to do it every... |
set output-radix 16(andset output-radix 10to switch it back).
|
According toISO 8601, time can be specified in different formats.
My program does not know which exact ISO 8601 format will be specified.
In this case, how can I convert it to time_t?
strptimerequires you to specify format (which I do not know before hand in my case).
Ultimate goal: is to compare 2 time_t timestam... |
If you are on a UNIX like machine, trygetdate. The interface is funky but works pretty good.
Which formats are recognized is
controlled by the file named by the
environment variable DATEMSK. This
file should contain lines of valid
format strings which could be passed
to strptime.
|
According to section 4.9.6.1 of theC89 draft, %d is a character that specifies the type ofconversionto be applied.
The wordconversionimplies, in my opinion, thatprintf("%d", 1.0)is defined.
Please confirm or refute this.
|
The conversion is the conversion of a language value to a lexical representation of that value.
Your theory is wrong; behavior is undefined. The spec says (7.19.6.1p8 and 9, using C99 TC2):
Theintargument is converted to signed decimal in the style [−]dddd.
And
If any argument is not the correct type for the corre... |
This question already has answers here:Closed12 years ago.
Possible Duplicate:Should I use char** argv or char* argv[] in C?
What is the difference between usingchar **argvandchar *argv[]for the second parameter to a c program. Does it affect the way the strings are passed? Thanks :-)
|
There is absolutely no difference. At all.
in C
```
void f(int*);
```
and
```
void f(int[]);
```
and
```
void f(int[42]);
```
are three completely identical declarations.
|
How can I authenticate to a web service hosted in IIS that is secured with Integrated Windows Authentication?
Do I use HTTP headers to add username and pwd?
I am trying to call this web service from UNIX in C.
|
I'm rather a newbie to IIS myself, and I'm just starting to dance around this topic, but I saw your note and thought it was crazy that no one has answered in so long!
I believe that the typical way that windows authenticates is Kerberos. You may have to go through some gyrations to get the Windows Kerberos server to... |
I have a question regarding the following code:
```
while((c = getc(pFile)) != EOF)
{
if(c != '\n')
{
input[index] = (char)c;
index++;
} else
{
input[index] = '\0';
index = 0;
}
}
```
In Windows, this c = getc line reads '\n' (code 10) twice. For example, I... |
Is the file physically the same, i.e. bit-by-bit, on the two platforms? That's asking for trouble, since the encoding for line ending differs.
|
is it possible to do an atomic write on the block level?as an example consider the following:
```
__global__ kernel (int atomic)
{
atomic+=blockid.x; //should be atomic for each block
}
```
|
You can do some atomic operations in CUDA. See Apendix B.11 Atomic Functions in the CUDA Programming Guide. i.e.:
```
__global__ void kernel (int *result)
{
atomicAdd(result, blockIdx.x); //
}
```
You can also exchange the value of a variable
```
__global__ void kernel (int *result)
{
atomicExch(result, bl... |
This question already has answers here:Closed12 years ago.
Possible Duplicate:What is ultimately a time_t typedef to?
In /usr/include/time.h time_t is defined astypedef __time_t time_t. What does this mean exactly? Is the type of time_t compiler specific? I have heard it is by default alongvalue.
|
The Standardsays:
7.23.1The types declared are [...] time_t [...] which are arithmetic types capable of representing times
You just need to retain that it is an arithmetic type: you can perform arithmetic with values oftime_ttype.
|
```
#include < stdio.h >
#include < string.h >
int main()
{
unsigned char a;
FILE *P;
P=fopen("mola.txt","r");
while((a=getc(P))!=EOF)
printf("%c",a);
}
```
Whats wrong with these code? When I compile it gives warning "comparison is always true due to limited range of data type." What does that warning mean?... |
You are storing the result ofgetcin achar. It should be anint. There's also aC FAQon it. Also you should check the return value of thefopen.
```
P=fopen("mola.txt","r");
if (NULL == P) {
perror("fopen"):
}
```
Also thewhilelooks fishy. Try indenting ?
```
while((a=getc(P)) != EOF)
printf("%c",a);
```
|
I have made a dll in Microsoft Visual Studio 2005. Then i am trying to use it in other project on the other computer in CodeBlocks IDE. Project is built, but when it use functions from dll i got an error: "The program can't start because MSVCR80D.dll is missing from your computer. Try reinstall the program to fix this... |
You're trying to run a debug version, which is linked to the debug version of the CRT. The latter is only available where VS has been installed. You should use the release version of your project on other machines (or manually copy all the dependent debug DLLs, which is not legal according to the license...).
|
Closed. This question needs to be morefocused. It is not currently accepting answers.Want to improve this question?Update the question so it focuses on one problem only byediting this post.Closed9 years ago.Improve this question
There some machines:
client C1, server : master, s1, s2
C1 connect to master and do the ... |
Request the GSSAPI toencryptyour communication. I use this with SASL and Active Directory. All traffic is securely wrapped.
|
popenstores o/p of the specified command into a file. How can I get similar functionality but o/p into a variable (i.e. in a char*) ?
|
No,popen()does not store output into a file. It specifies astream, whichmightrepresent to a file on disk but which might also be at e.g. a pipe or socket. Streams are more abstract than files.
To have a pipe, you would open the pipe using e.g.pipe()and then callfdopen()on the proper end of the resulting pipe.
|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed12 years ago.
I want to read a text file line on ... |
POSIXprovidesregcomp,regexec,regfree, and friends for regular expression matching. If you are using C++, then you can use theRE2library for faster, safer regular expression matching. If all you need to do is find an exact match like "hello", you won't even need a regex library like these.
Yes, this is something you c... |
I want to suspend (pause) a forked process at startup and resume it later on. Is there any way to do that with POSIX or Solaris.
|
Why not just callpause()in code of child process after fork?
|
Am quite a novice here so please excuse me if I am sounding too stupid.
I am working on Linux(Fedora). I have three partions namely: Log, Backup and File system. On boot the File system is mounted. Now, I need to mount the file systems on Backup and Log and access/write to them from within a C program which I have in ... |
Seemount(2)andgetmntent(3)
|
On GCC Linux, is there a way I can add a file resource to be embedded statically into the C program, and then how would I expand that out to /tmp from main()?
|
You can use objcopy to embed the resource, and then normal file operations to create the file in /tmp.
If you compile this program:
```
#include <stdio.h>
extern char _binary_resource_bin_start, _binary_resource_bin_end;
int main() {
FILE*out = fopen("/tmp/rsrc.bin","wb");
fwrite(&_binary_resource_bin_start,
... |
Stumbled upon this example of bad C++ code in a blog post, without any explanation as to why it is considered "bad". I have my own ideas, but would like to hear experienced C++ devs on this.
```
unsigned int Fibonacci (unsigned int n)
{
if (n == 0 || n == 1)
return n;
else
return Fibonacci (n ... |
Perhaps because it runs in exponential time?
|
I have for loop doubt that I need to ask .
once i saw in coding something like
```
for(i = 0; i<10; i+)
```
My doubt is why &when in for loop we use sayi+ori-rather thani++ori--
Thanks in advance
|
It won't work, doesn't the compiler return an error if you do? ( or atleast a warning.. )
Just use ++i or i++
|
I am getting a TLB (Load Word or Instruction Fetch) exception in VxWorks. When I analyze further I understood that the memory address which is being referred doesn't point to a valid memory location.
As far as I understand, this problem could be happening because of some memory corruption (possible memory overwrite).... |
Yes, certain processor architectures and throw TLB exception when code compiled with certain compiler flags access memory with certain attributes. e.g. PowerPC on uncached memory with compiler flags that lead to aligned access to unaligned data.
Yes, but without additional information "Yes" is not helpful for you.
|
I have a char pointer returned from a function, and i want to double check its value using the IF statement how should i implement this one in C.
substring function fromhere
I want it something like this
```
if (substring("xxxNameYYY",0,3)=="xxx"){
//do this
} else {
//do that
}
```
the above if statemen... |
You cannot compare string like that in C, you have to usestrcmp(str1, str2) == 0to check if they are equal.
In your case:
```
char * substr = substring("xxxNameYYY",0,3);
if (strcmp(substr, "xxx") == 0) {
/* TODO */
}
else {
/* TODO */
}
```
|
When dealing with variable argument lists in C, I was just curious to know which data structure might a compiler be using when storing the variable arguments in a list.
Is it an array of void pointers?Is it a linked list of void pointers?or anything else?
|
No structure. The calling code just puts the arguments on the stack, it's the vararg function's responsibity to decode them properly.
For example in case of printf, the first argument is fixed, a c string, and the rest is decoded based on what's in the string. C just gives you tools to access these elements so you do... |
I'm using C in Linux. How do I show a progress indicator that will let me know when the program (or parts of the program) will complete? For example, it could be something like "Searching...67%" and the percentage will keep increasing until the Searching portion ends.
Thank you.
|
Write a'\r'character to stdout to return the cursor to the beginning of the line so you can overwrite the line. For example:
```
for (i=0; i<100; i++) {
printf("\rSearching...%d%%", i);
fflush(stdout);
sleep(1);
}
```
|
I can't seem to get libcurl to work. I've installed it with the cygwin package installer but when I run it in the cygwin bash shell with:
```
gcc -Wall -lcurl -g blah.c -o blah
```
It I get:
curl/curl.h: No such file or directory`,
then following errors that provoked by the#include <curl/curl.h>not working.
|
```
find / -name curl.h
```
if curl.h is found, compile with this:
```
-I/directory/that/contains_the_curl_header
```
but do not include 'curl.h', just the directory containing it. If you are doing it like this:
```
#include <curl/curl.h>
```
then only use the directory that contains the curl directory as the-Ipa... |
It's my understanding that uint64_t defined by C99 (stdint.h) is defined to be 8 bytes (= 64 bits) of length, thus allowing for a maximum value of 2^64 - 1. However, when I try the following code snippet, the uint64_t overflows, even though it's nowhere near 2^64 - 1:
```
uint64_t Power10(int exponent)
{
int i = ... |
You need to print with"%" PRIu64conversion. Don't forget to add the right include!
```
#include <inttypes.h>
int main(void) {
printf("Power10(12) is %" PRIu64 "\n", Power10(12));
return 0;
}
```
|
I am running into some C code that is using the getservbyname_r() function.
I found this overview of it:
http://publib.boulder.ibm.com/iseries/v5r2/ic2928/index.htm?info/apis/tsgservn.htm
but I am not sure what the 'service database file' is or how it is populated.
I am running on Red Hat EL 6. (I'm also not sure... |
In the traditional flat-file world it's/etc/servicesor/etc/inet/services; typically it's part of the base system install. It's also possible for entries to be read from NIS, LDAP etc., depending on the system's naming services configuration (/etc/nsswitch.conf).
|
So far, I was able to call member functions which belong to a class for a struct. CEDET can give the suggestion nicely. However, for non-member functions, such as functions in C, which usually does not belong to anything i.e. functions like sort, qsort.... I can only auto-complete with CEDET if I have an instance of a... |
CEDET works fine for such functions - you need to be sure, that all necessary headers are included into your source code. You can also force CEDET to re-parse buffer withM-x bovinatecommand. But it's better to use CEDET from bzr repository, because fixes for C & C++ mode are made very often.
If it still don't worki... |
I have seen the given two makefiles as follows:
```
all: thread1 thread2 thread3
CFLAGS=-I/usr/include/nptl -D_REENTRANT
LDFLAGS=-L/usr/lib/nptl -lpthread
clean:
rm -f thread1 thread2 thread3
######################
all: thread1 thread2 thread3
CFLAGS=-D_REENTRANT
LDFLAGS=-lpthread
clean:
rm -f thread1 t... |
Your question is answered here
gcc: Do I need -D_REENTRANT with pthreads?
Essentially all you need is
gcc thread1.c -o thread1 -pthread
and gcc will handle all the defines for you.
|
I have very little experience with compression algorithms; my experience just comes from running the tar czvf command. Is there a way to compress a char array in C?
My main focus is speed and memory optimization. I'm receiving data from serial ports, and then writing them out to a log file right now. I want to compre... |
zlib has already been mentioned in the comments. Since you mention ASCII, you might be interested in particular in the functions:
```
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
```
|
What is the best way to generate UTF-8 JSON in C? I've looked atJansson, but it seems extremely bulky. Is there any other good low-dependency library for creating and reading JSON objects/strings in C?
|
Perhaps the JSON module from CCAN?http://ccodearchive.net/It doesn't even depend on anything else from CCAN, and consists of exactly two filesjson.candjson.h
(The JSON module is herehttp://git.ozlabs.org/?p=ccan;a=tree;f=ccan/json)
|
This question already has answers here:Whitespace before %c specification in the format specifier of scanf function in C(2 answers)Closed5 years ago.
```
#include <stdio.h>
int main(int argc, char* argv[]) {
char c;
scanf(" %c", &c);
printf("%c\n", c);
return 0;
}
[root@test]# ./scanf
a
a
[root@test]# ./sc... |
White space (such as blanks, tabs, or newlines) in the format string match any amount of white space, includingnone, in the input.
http://www.manpagez.com/man/3/scanf/
|
I'm using EXTRA_DIST within a Makefile.am to copy some folders:
EXTRA_DIST = input/
The problem is that it repeats the directory name input/input/
Do you know any solution for this problem? is this a bug of automake?
|
I have found the solution. With: "EXTRA_DIST = input" instead of "EXTRA_DIST = input/" works fine
|
When a terminal disconnects, kernel will notify controlling terminal by sending aSIGHUPto it. After that, controlling process sendsSIGHUPto all processes in the same session. What happens when those processes catch theSIGHUPbut do some other thing instead of terminating in signal handler?
|
They go on with their business and terminate
When they decideWhen they receive another signal
|
should we explicitly join a thread to finish? I mean is this like process world: when we don't wait for them to finish we got zombie processes.
|
Not necessarily; you can always detach a thread if you don't wan't to explicitly wait for it.
There are a few things to consider:
If you don't join a non-detached thread it will become a zombie thread (yes, there are such things)If you don't join a thread, your main thread might end before the "child" endsOnce you d... |
```
typedef struct {
unsigned char a,
unsigned char b,
unsigned char c
}type_a;
typedef struct {
unsigned char e,
unsigned char f[2]
}type_b;
type_a sample;
sample.a = 1;
sample.b = 2;
sample.c = 3;
```
How do I typecast it and assign new value like:
```
sample = (type_b)sample; // syntax error
sample.f[1... |
You should really try it out yourself.
```
sample = (type_b)sample; /* Can't cast a structure to
another structure. */
sample.f[1] = 'a'; /* sample is still of type type_a,
and doesn't have an `f` field. */
```
|
Is it possible to cycle and extract its value for every item in an enum, e.g:
```
enum {
item 1 = 1,
item 2 = 7,
item 3 = 'B'
} items;
```
To say, an array. Possible?
|
Do you mean to construct an array with one element for each value of the enum? Such that you would end up with an array{1, 7, 'B'}?
Not possible. An enum is not much more than a bunch of compile-time constants. At runtime, they are effectively just ints. The compiler doesn't even check to make sure you are putting va... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.