question stringlengths 25 894 | answer stringlengths 4 863 |
|---|---|
Im doing some debugging on hardware with a Linux OS.
Now there no way for me to know if any of it works unless I can check the allocated ram that I asked it to write to.
Is there some way that I can check what is in that block or RAM from an external program running in the same OS?
If I could write a little program... |
/dev/memcould come to use. It is a device file that is an image of the physical memory (including non-RAM memory). It's generally used to read/write memory of peripheral devices.
Bymmap()ing to it, you could access physical memory.
See thislinux documentation project page
|
I need using steps (Step over, Step over instruction...) and breakpoints.
But the options Step over, Step over instruction and ect. are disabled in menu Run.
And when I put breakpoint into program, program don´t stop on this breakpoint.
I found that I must turn off optimization of compiler and linker. But I don´t k... |
You need to compile in debug mode. What toolchain do you use for compiling? CMake? If so, set CMAKE_BUILD_TYPE to Debug.
|
How can i make a program like internet download manager to download a file of given link from internet. Could use socket programming C to download a file from internet.
Your help will be appreciated.
Thanks.
|
Create a socket usingsocket()Callconnect()on it.Send aGET /path/filename HTTP/1.0\r\n\r\nrequest using eithersend()orwrite()properly.Receive the response using eitherrecv()orread()properly.Parse the response to find out if the request succeeded and what format the file data is being sent as.Receive the file data, if p... |
I tried:
```
#include<stdio.h>
main()
{
int a=10000;
unsigned char cp1=0,cp2=0,cp3=0,cp4=0;
cp1 = (a & 0xff000000) >> 24;
cp2 = (a & 0x00ff0000) >> 16;
cp3 = (a & 0x0000ff00) >> 8;
cp4 = (a & 0x000000ff) ;
printf("%d %d %d %d\n",cp1,cp2,cp3,cp4);
}
```
My output is:
```
0 0 39 1... |
```
a = 0010 0111 0001 0000
0xff00 = 1111 1111 0000 0000
(a & 0xff00) = 0010 0111 0000 0000
(a & 0xff00)>>8 = 0000 0000 0010 0111 //shift the bits of above ANDing 8 times to right
0000 0000 0010 0111 = 39 in decimal
```
|
The following piece of code compiles and runs withgcc version 4.7.2 (Debian 4.7.2-5):
```
#include <stdio.h>
int main()
{
const volatile x = 3;
volatile const y = 4;
return 0;
}
```
Should I assume that the order of const and volatile is irrelevant? I tried reading up here :encpp refand it doesn't say ... |
Yes, the order is irrelevant. In C++, the relevant specification is in 7.1p1,decl-specifieranddecl-specifier-seq, which basically explain that there is a sequence of relevant keywords, and 7.1.6, which listsconstandvolatileas two these keywords. Note that the production is weird enough that these are valid as well, th... |
Im doing some debugging on hardware with a Linux OS.
Now there no way for me to know if any of it works unless I can check the allocated ram that I asked it to write to.
Is there some way that I can check what is in that block or RAM from an external program running in the same OS?
If I could write a little program... |
/dev/memcould come to use. It is a device file that is an image of the physical memory (including non-RAM memory). It's generally used to read/write memory of peripheral devices.
Bymmap()ing to it, you could access physical memory.
See thislinux documentation project page
|
I need using steps (Step over, Step over instruction...) and breakpoints.
But the options Step over, Step over instruction and ect. are disabled in menu Run.
And when I put breakpoint into program, program don´t stop on this breakpoint.
I found that I must turn off optimization of compiler and linker. But I don´t k... |
You need to compile in debug mode. What toolchain do you use for compiling? CMake? If so, set CMAKE_BUILD_TYPE to Debug.
|
How can i make a program like internet download manager to download a file of given link from internet. Could use socket programming C to download a file from internet.
Your help will be appreciated.
Thanks.
|
Create a socket usingsocket()Callconnect()on it.Send aGET /path/filename HTTP/1.0\r\n\r\nrequest using eithersend()orwrite()properly.Receive the response using eitherrecv()orread()properly.Parse the response to find out if the request succeeded and what format the file data is being sent as.Receive the file data, if p... |
I tried:
```
#include<stdio.h>
main()
{
int a=10000;
unsigned char cp1=0,cp2=0,cp3=0,cp4=0;
cp1 = (a & 0xff000000) >> 24;
cp2 = (a & 0x00ff0000) >> 16;
cp3 = (a & 0x0000ff00) >> 8;
cp4 = (a & 0x000000ff) ;
printf("%d %d %d %d\n",cp1,cp2,cp3,cp4);
}
```
My output is:
```
0 0 39 1... |
```
a = 0010 0111 0001 0000
0xff00 = 1111 1111 0000 0000
(a & 0xff00) = 0010 0111 0000 0000
(a & 0xff00)>>8 = 0000 0000 0010 0111 //shift the bits of above ANDing 8 times to right
0000 0000 0010 0111 = 39 in decimal
```
|
Im doing some debugging on hardware with a Linux OS.
Now there no way for me to know if any of it works unless I can check the allocated ram that I asked it to write to.
Is there some way that I can check what is in that block or RAM from an external program running in the same OS?
If I could write a little program... |
/dev/memcould come to use. It is a device file that is an image of the physical memory (including non-RAM memory). It's generally used to read/write memory of peripheral devices.
Bymmap()ing to it, you could access physical memory.
See thislinux documentation project page
|
I need using steps (Step over, Step over instruction...) and breakpoints.
But the options Step over, Step over instruction and ect. are disabled in menu Run.
And when I put breakpoint into program, program don´t stop on this breakpoint.
I found that I must turn off optimization of compiler and linker. But I don´t k... |
You need to compile in debug mode. What toolchain do you use for compiling? CMake? If so, set CMAKE_BUILD_TYPE to Debug.
|
How can i make a program like internet download manager to download a file of given link from internet. Could use socket programming C to download a file from internet.
Your help will be appreciated.
Thanks.
|
Create a socket usingsocket()Callconnect()on it.Send aGET /path/filename HTTP/1.0\r\n\r\nrequest using eithersend()orwrite()properly.Receive the response using eitherrecv()orread()properly.Parse the response to find out if the request succeeded and what format the file data is being sent as.Receive the file data, if p... |
I tried:
```
#include<stdio.h>
main()
{
int a=10000;
unsigned char cp1=0,cp2=0,cp3=0,cp4=0;
cp1 = (a & 0xff000000) >> 24;
cp2 = (a & 0x00ff0000) >> 16;
cp3 = (a & 0x0000ff00) >> 8;
cp4 = (a & 0x000000ff) ;
printf("%d %d %d %d\n",cp1,cp2,cp3,cp4);
}
```
My output is:
```
0 0 39 1... |
```
a = 0010 0111 0001 0000
0xff00 = 1111 1111 0000 0000
(a & 0xff00) = 0010 0111 0000 0000
(a & 0xff00)>>8 = 0000 0000 0010 0111 //shift the bits of above ANDing 8 times to right
0000 0000 0010 0111 = 39 in decimal
```
|
Is this legal in C?
```
struct Doubles
{
double a,b,c;
};
void foo(struct Doubles* bar)
{
double* baz = (double*)bar;
baz[0]++;
baz[1]++;
baz[2]++;
}
```
I know that it "works" on MSVC 2010, but I don't know if it's legal, or if different layouts could cause UB.
|
This leads to undefined behaviour. The layout of the struct is not totally prescribed by the standard. For instance, there may be padding.
|
strlen() is terminated by null right? So how come both char c[]={'1','1'} and char d[]={'1','1','\0'} gives the same output 2 when strlen(c) and strlen(d) is used?
|
The former is undefined behavior; it could output 2, it could also output 500, terminate your program or destroy your computer.
|
Is there any difference between
```
double x;
x=0;
```
and
```
double x;
x=0.0;
```
might be a stupid question but i can't really find the answer anywhere
|
In practice, there doesn't have to be any difference although there is an implicit conversion in the first case since0is anint.
I tried it (onassembly.ynh.io). This C code:
```
#include <stdio.h>
int main(void)
{
double x, y;
x = 0;
y = 0.;
printf("x=%g and y=%g\n", x, y);
return 0;
}
```
generated th... |
Closed. This question isopinion-based. It is not currently accepting answers.Want to improve this question?Update the question so it can be answered with facts and citations byediting this post.Closed9 years ago.Improve this question
Is there any reason to print errors on stdout and not on stderr?
I see some People ... |
It's lazyness. stderr was created to print error messages, so you can redirect the output of a program without having mixed error messages. Also, I think stderr is unbuffered by default, so if your program crash, all the error messages up to the point where it crashed are printed (this behaviour can be modified by the... |
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
What changes does it happen in the program when the exception is caught? How does thrown ... |
Well, I tried implementing simple exception-handling in C 2 years ago. Let me show it to you.
https://github.com/dlarudgus20/CTryCatch
(In fact, I made the github repository to practice as soon as I saw you question - it's my first repository >o< Thank you to give me the opportunity to use github!)
|
I have a portable library that in one place needs to do X if compiled under Visual Studio or just with Microsoft's C/C++ compiler, and Y otherwise. What#defineshould I look for?
|
Aquick Google searchleads topredefined macros on MSDNwhich lists all macros predefined by MSVC. Out of these,_MSC_VERis likely the best candidate.
|
I am definitely new to the C game, and would love some help with the following code snippet:
```
#include <stdio.h>
int main() {
int cases;
scanf("%d", &cases);
printf("%d", cases);
int i;
int *heights;
for(i=0; i<cases; i++){
scanf("%d", &heights[i]);
}
return 0;
}
```
I u... |
Usemallocto dynamically allocate space forheights.
```
int *heights = malloc(cases*sizeof(int));
```
Andfreepointer by callingfree(heights)when you are done withheights.
For small value ofcasesyou can usevariable length arrays:
```
int heights[cases];
```
and do not forget to compile your code in C99 mode (-std=c... |
For example, what is the difference between
```
(*user1).id
```
and
```
*user1.id
```
It would be much better to have a example to explain.
Thanks!
|
(*user1).iddereferencesuser1, which must be a pointer to a structure containing anidfield, and gets theidfield out of that structure. 100% equivalent touser1->id.*user1.idgets fieldidout ofuser1which must be a structure (not a pointer to a structure) contaning anidfield. It then dereferences that value, meaning thei... |
I'am new to the OpenCL. How can i make a delay in OpenCL Kernel script without making loops? I have a code that's in some circumstances needs to wait for some time and then resume execution like so
```
__kernel void test(uint4 value,uint4 delay)
{
uint id = get_global_id(0);
//some code
for(uint i=... |
The OpenCL spec is designed for data crunching. Not for wait/sleeps. Even if you may achieve it, you will be breaking a lot of the good design rules of OpenCL.
In fact, many GPUs will crash or kill the execution if you try to sleep them.
Please reconsider what you need, and if it is suitable for parallel computing.
|
StrangeCreateFilebehaviour. I am tiring to open file
```
HANDLE hFile = CreateFile(L"E:\\temp\\1.txt",
GENERIC_READ,
FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("Could not... |
Get rid of theLprefix of your filename string. You are calling the narrow version ofCreateFile(CreateFileA) and passing in a wide string.
Alternatively, you can set VS to build your app using Unicode.
In either case, you should use the_T()macro to set the appropriate string type. i.e.
```
HANDLE hFile = CreateFile(... |
I want to return the address of variablekin functionfunc(). Here is are the 2 functions.
main()Function
```
#include <stdio.h>
main()
{
int* j;
int* func();
j= func();
printf("\n%d",*j);
}
```
func()Function
```
int* func()
{
static int k=30;
return (&k);
}
```
I wantedint *func()to return the a... |
kis a local variable who exists only inside the functionfunc.So you are returning the address wherekdoes not exist.It isundefined behavior.
You could allocate dynamic memory fork:
```
int *k = (int*)malloc(sizeof(int));
*k = 30
return k;
```
Do not forget to free the memory in yourmain
```
free(j);
```
|
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.Questions asking us torecommend or find a tool, library or favorite off-site resourceare off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead,describe the problemand what has been do... | ERROR: type should be string, got "\nhttps://github.com/seanmiddleditch/libtelnet\n\nThis opensource code will help you I think\n" |
This question already has answers here:__FILE__ macro manipulation handling at compile time(9 answers)Closed9 years ago.
I want to print the filename that is being used in my project.
But if I use__FILE__, it prints entire path along with the file name which is long in my case and disturbs the log indents.
Can anyon... |
In your C code, you might use instead of__FILE__the expressionbasename(__FILE__); however, this has the disadvantage of callingbasenameat every occurrence.
Alternatively, compilepath/foo.cwith a command like
```
gcc -Wall -c -g -DBASE_FILE=\"foo\" path/foo.c
```
(you could have a genericmakerule giving that : withG... |
I understand that there is nothing preventing linux to assign descriptors any random numbers in range 0...2^32 when I create new socket.But what reality is?In my application (web server) I need a mapping structure that maps descriptor into a "connection structure". I understand that some kind of RB-Tree (int -> connec... |
File descriptors are always assigned from the lowest available number. This is guaranteed by POSIX.
|
StrangeCreateFilebehaviour. I am tiring to open file
```
HANDLE hFile = CreateFile(L"E:\\temp\\1.txt",
GENERIC_READ,
FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("Could not... |
Get rid of theLprefix of your filename string. You are calling the narrow version ofCreateFile(CreateFileA) and passing in a wide string.
Alternatively, you can set VS to build your app using Unicode.
In either case, you should use the_T()macro to set the appropriate string type. i.e.
```
HANDLE hFile = CreateFile(... |
I want to return the address of variablekin functionfunc(). Here is are the 2 functions.
main()Function
```
#include <stdio.h>
main()
{
int* j;
int* func();
j= func();
printf("\n%d",*j);
}
```
func()Function
```
int* func()
{
static int k=30;
return (&k);
}
```
I wantedint *func()to return the a... |
kis a local variable who exists only inside the functionfunc.So you are returning the address wherekdoes not exist.It isundefined behavior.
You could allocate dynamic memory fork:
```
int *k = (int*)malloc(sizeof(int));
*k = 30
return k;
```
Do not forget to free the memory in yourmain
```
free(j);
```
|
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.Questions asking us torecommend or find a tool, library or favorite off-site resourceare off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead,describe the problemand what has been do... | ERROR: type should be string, got "\nhttps://github.com/seanmiddleditch/libtelnet\n\nThis opensource code will help you I think\n" |
This question already has answers here:__FILE__ macro manipulation handling at compile time(9 answers)Closed9 years ago.
I want to print the filename that is being used in my project.
But if I use__FILE__, it prints entire path along with the file name which is long in my case and disturbs the log indents.
Can anyon... |
In your C code, you might use instead of__FILE__the expressionbasename(__FILE__); however, this has the disadvantage of callingbasenameat every occurrence.
Alternatively, compilepath/foo.cwith a command like
```
gcc -Wall -c -g -DBASE_FILE=\"foo\" path/foo.c
```
(you could have a genericmakerule giving that : withG... |
I understand that there is nothing preventing linux to assign descriptors any random numbers in range 0...2^32 when I create new socket.But what reality is?In my application (web server) I need a mapping structure that maps descriptor into a "connection structure". I understand that some kind of RB-Tree (int -> connec... |
File descriptors are always assigned from the lowest available number. This is guaranteed by POSIX.
|
Well, I'm not sure how I should write a function using recursive descent parse to parse a grammer like the below. Actually, I'm not sure if I was doing right it...
BNF:
```
A : B | A '!'
B : '[' ']'
```
pseudo-code:
```
f()
{
if(tok is B)
parse_b();
return somethingB
else if(????) how will I kn... |
See my SO answer to another similar question ondetails on how to build a recursive descent parser.
In particular it addresses the structure of the parser, and how you can pretty much derive it by inspecting your grammar rules, including handling lists.
|
In a method I have am*nmatrix and an array (allocated as am*1matrix), unfortunately during compilation I get this error:
```
main.c:337:30: error: invalid operands to binary * (have ‘float’ and ‘float *’)
yp += matrixA[i][j] * listB[j];
```
the full code of the method is this
```
float error(float ... |
listB[j]is offloat *type. You are multiplying it withfloattype. Change
```
yp += matrixA[i][j] * listB[j];
```
to
```
yp += matrixA[i][j] * listB[j][i];
```
|
I've been looking through GSL and Boost libraries to find thedilogarithm function, but I have not found it.
Is there an implementation available for C++/C of this function?
|
GSL seems to have it:https://www.gnu.org/software/gsl/manual/html_node/Dilogarithm.html
gsl_sf_dilog.h
```
double gsl_sf_dilog (double x)
int gsl_sf_dilog_e (double x, gsl_sf_result * result)
int gsl_sf_complex_dilog_e (double r, double theta, gsl_sf_result * result_re, gsl_sf_result * result_im)
```
|
I have installed the libbmp library from this linkhttps://code.google.com/p/libbmp/and I have made all the required steps to complete with the installation.
When I try to use it, by including the bmpfile.h like the example on the download page:
```
#include <bmpfile.h>
```
I get this error:
```
fatal error: bmpfile... |
Presumably it was installed to/usr/local/includeand your compiler doesn't look in that location. To fix this, you should set yourCPATHvariable to point there:
```
CPATH=/usr/local/include
export CPATH
```
This is typically done in your.bashrcor similar, or in your IDE if you're using one.
For more info check your c... |
I am sorry if this is a naive question, but there's something I can't get my head around.
Why is the C++ standard library bundled with different compiler implementations (g++'slibstdc++andclang'slibc++) instead of coming bundled with a (UNIX-like) Operating System, just as, say the C standard library does? Why isn't ... |
The basic reason is that there is no standard C++ ABI -- every compiler tends to have its own ABI that is different from and incompatible with that of other compilers. On the other hand, most OSes define a standard C ABI that they use and supply a standard C library for, and all C compilers for that OS support that A... |
I'm trying to use a function in C using JNA:
C:
```
int addHoliday(unsigned char* data);
```
JAVA:
```
int addHoliday(byte[] data);
```
I'm passing my byte[] with information, but in C I'm using the same pointer to write a response. Can I catch the same byte[] with the new information?
|
Yes, primitive arrays work just like memory buffers when used in a direct function call. The native code will see a consistent buffer for the duration of the native call, and your Java code will see in thebyte[]whatever data was written by the native code.
As for the signedness of the data, anyunsigned charelements ... |
I have a buffer:
```
typedef struct _MESSAGE {
UCHAR Data[];
} MESSAGE, *PMESSAGE;
```
That is used for communication(to pass parametrs, like ulong) between driver and user mode app. I used it as UCHAR type. But now i want also send wide characters with this buffer, should i change it type
to WCHAR or PCHAR?
Wh... |
You don't need to change data type, it is a generic byte (a raw data stream type). Try this it work:
```
typedef struct _MESSAGE {
UCHAR Data[200];
} MESSAGE_T, *PMESSAGE_T;
int byte_offset = 0; // byte offset inside your data stream
wchar_t MyMessage1[] = L"Ciao Mondo";
wchar_t MyMessage2[100];
MESSAGE_T M... |
I'm looking for a creative solution for making sure that variables delivered to a specific macro are declared with type volatile in C language, with TMS470 compiler. meaning:
good method:
```
volatile int *_p_reg;
VOLATILE_MACRO(_p_reg);
```
compilation failure:
```
int *_p_reg;
VOLATILE_MACRO(_p_reg);
```
I ... |
I wouldn't expect there to be any, but of course it's totally up to the compiler.
You could of course re-architect it so that the macro does the whole definition, i.e.
```
#define VOLATILE_MACRO(t, p) volatile t p
```
and use it like:
```
VOLATILE_MACRO(int, _p_reg);
```
but of course that might not work for you.... |
This question already has answers here:visual studio express complains missing ';' after type in c program(2 answers)Closed9 years ago.
My code keeps generating the error:
error C2065: 'i' : undeclared identifier when iterating in C
This is the section it is complaining about specifically:
```
for (int i = 0; i < (... |
Visual Studio 2010 only supports C89, not C99. In C89, a variable must be declared in the beginning of a block like this:
```
void foo(void)
{
int i;
for (i = 0; i < gamesToPlay; i++)
{
//do something
}
}
```
|
I have a struct in c as follows:
```
typedef struct edgenode
{
int value;
struct edgenode * next;
};
```
I wish to create an array of pointer of edgenodes.
So, I can do edgenode * array[50].
But, how do I go about allocating memory dynamically for this?
Will it be,
```
edgenode ** array = malloc(sizeof(edgen... |
You can do like this
```
edgenodes * array = malloc(50 * sizeof *array);
```
You can initilize it byNULLas follows
```
for(i = 0; i < 50; ++i)
array[i] = NULL;
```
For allocating memory for each instance you need
```
for(i = 0; i < 50; ++i)
array[i] = malloc(sizeof *array[i]);
```
|
So I encountered the following code in a library for C for RF communication :
```
#define __COMB(a,b,c) (a##b##c)
#define _COMB(a,b,c) __COMB(a,b,c)
```
Which is basically used to create various names for constants and functions. It just concatenates the parameters.
What I don't get is the 2nd line. Is there a reas... |
This is a hack to trick the C preprocessor to pre-expand the parameters before they're concatenated. This kind of decoupling is required in certain some situations, for example if__COMBis to be used in a preprocessor macro parameter stringification.
|
what is the best solution to copy a char array-which may contains multiple null characters-to another char arrays of arrays?for example:
char src[11] = "ab\0cde\0\0fg"
char des[2][6];
at the end
```
des[0] should be ---> ab\0cd + \0
des[1] should be ---> e\0\0fg + \0
```
note: it should be done just in ... |
you are looking formemcpy
```
memcpy(des[0] // target void *
, src // source void *
, 5 // number of bytes to copy
);
des[0][5] = '\0';
memcpy(des[1] // target void *
, src + 5 // source void *
, 5 // number of bytes to copy
);
des[1][5] = '\0';
```
|
I would like to know if it is possible to execute two consecutive instructions in C, in an atomic way. This means that I don't want any other process executing in the operating system (Linux) consume processing time while this instructions are executing.
Thanks!
|
No. It's not possible for one process to block everyone else. That would be pretty bad for a multi-user system and even on single user systems it has quite horrible failure modes.
You can increase your priority levels, but even then you will be preempted by interrupts and system level processes.
The best you can do ... |
Anyone who is familiar withasteriskknows you can connect to running asterisk application by using "asterisk -r" command and looking at what asterisk is up to.
My question is using c/c++ , how is it achieved? what headers / libraries are used? I have been searching around for long but can not find anything relevant.
... |
When first instance of asterisk is run, it opens socket server which is handling communication with daemon.
asterisk -ris nothing more than socket client
|
How do I convert the following Objective-C code into Swift code?
```
#define MAX_SIZE 11
char buffer[MAX_SIZE];
time_t time = [[NSDate date] timeIntervalSince1970];
strftime(buffer, MAX_SIZE, "%-l:%M\u2008%p", localtime(&time));
NSString *dateString = [NSString stringWithUTF8String:buffer];
NSLog(@"dateString: %@", d... |
As the commentators @BryanChen and @JasonCoco said, use NSDateFormatter.
```
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd 'at' h:mm a" // superset of OP's format
let str = dateFormatter.stringFromDate(NSDate())
```
A full description of the format strings is available in"Data Formatti... |
So I'm trying to write some C code by looking at the assembly here:
```
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
addl 8(%ebp), %eax
movzbl (%eax), %eax
movsbl %al,%eax
popl %ebp
ret
```
I see that I have two variables, and they are being added together, then I'm getting lost when looking when t... |
A corresponding C function would be something like
```
char fn(char * string, int index)
{
return string[index];
}
```
Specifically, themovzblinstruction fetches the byte stored at the sum of the two parameters, zero pads it, and stores it intoeax. Themovsblinstruction takes the lowest byte of eax, sign extends ... |
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.This question does not appear to be abouta specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic onanother Stack Exchange site,... |
A watchdog is a mechanism that periodically tests whether a process or thread is running properly. If it's not, it either restarts it or notifies an administrator, depending on the needs of the application.
The details of how you implement this will depend on the application design.
|
I’m trying to deference a char pointer to a char array inside a function:
```
void getword(char *word)
{
*word = "bar";
}
int main()
{
char defword[4] = "foo";
getword(defword);
printf("%s\n", defword);
return 0;
}
```
I would expect to get "bar" as output but I seem to get the completely unr... |
The type of a dereferencedchar *ischar— a primitive value type. In this case,*wordis the same asword[0].
The type of"bar"isconst char *— a pointer type.
You are assigning the value of a pointer to a character. I'm doubtful your compiler let that happen without squawking mightily.
In any event, look intostrcpy. Leav... |
If I want to debug my program I call it like this:
```
gdb ./myprog
$ run < input.txt
```
But now I want to execute it line by line, but how can I do this? I know thestepcommand but I can only call it, if the run command was called before. Do I have to stop the execution directly after the run command?
|
Gdbhas astartcommand, which takes the same arguments as theruncommand. After starting the program, it stops as soon as possible, usually at the start of themainfunction. After that, you can use thestepcommand and any other commands that require a live process.
Reference:Debugging with GDB: Starting your Program
|
What does the constant MAP_FIXED do for mmap?
I've read it in the manual but still don't understand its purpose and for which cases it's good.
|
MAP_FIXED specifies that the mmap'd memory should be at the virtual address passed as the first argument tommap(). This has very limited usage in modern user programs and in fact some operating systems simply return an error if MAP_FIXED is specified.
One possible use for MAP_FIXED is when implementing a memory allo... |
I've written a function that interprets serial data (CAN) and currently returns a float. I'd like the function to include an argument wherein the user specifies a return type in a string, and the function returns a value of that type. It's just a convenience thing, to avoid having to write multiple functions that shar... |
Pass a void pointer to the type of data you want returned.
```
void foo(char* szType, void *pOut) {
switch (szType[0]) {
case 'I': *(int*)pOut = 1; break;
case 'F': *(float*)pOut = 1; break;
}
}
```
use like this:
```
int a;
float b;
foo("I", &a);
foo("F", &b);
```
|
I am using 64 bit gcc compiler on a intel machine to compile following code
```
void main(void) {
unsigned long L = 1, R = "123";
printf("%s %lu %lu", "1st",L, R);
printf("%s %d %s", "2nd", L, R);
}
```
I get following output
1st, 1, 42059132nd, 1, 123
my confusion is that when I take %lu what is this ... |
The reason that123gets printed correctly is a coincidence: it happens that in your architecture an address can fit intounsigned long. This is by no means a guarantee, so what you see is undefined behavior that simply "went your way".
The standard defines an integral typeuintptr_tthat is guaranteed to be capable of ho... |
This code looks like it is supposed to reverse the string , but instead it reverses only the first character and the output is :- delloworlh
Any ideas why this is happening
```
int main()
{
char p[] = "helloworld";
char t;
int i, j;
for(i=0,j=(strlen(p)-1); i<j; i++)
{
t = p[i];
... |
In your loop, you use the condition:i<jSo, after i reaches j/2, it starts to fix the reverse string again back to its original form.So you must change your condition toi<j/2+1;
|
i'm trying to understand why this code give me a segmentation fault!researchis a string and it's printing my tokens but after that i have a segmentation fault.Could you help me please ?
```
char buf[MAX_CHARS_PER_LINE];
strcpy(buf, research.c_str());
int n = 0;
const char * token[MAX_TOKENS_PER_LINE] = {};
for (n =... |
No pre-increment
```
if (!token[n]) break;
```
Always use strncpy when copying to a fixed length char array - not strcpy.
|
Which of these codes is appropriate and why ?
code1:
```
void fun(int *p)
{
*p=200;
}
main(){
int *i_ptr;
fun(i_ptr);
printf("%d", *i_ptr);
}
```
Code2:
```
void fun(int *p)
{
*p=200;
}
main(){
int i;
fun(&i);
printf("%d", i);
}
```
is it okay to pass pointer's address ?
|
You asked:
Which of these codes is appropriate and why ?
The first one will lead to undefined behavior sincei_ptrhas not been initialized to point to a valid memory.
You can change it to:
```
int main(){
int i;
int *i_ptr = &i;
fun(i_ptr);
printf("%d", *i_ptr);
}
```
and it will be OK.
BTW, I also ad... |
String of 3 numbers of any length - embedded in spaces and tabs, represented below with the\tmarker:
```
123456789 \t 12345 \t6789\n
```
There can be any amount and combination of space and tab' between the numbers.
For example, this is also valid:
```
1 \t \t2\t\t\t\t\t \n3\n
```
What is the most efficient wa... |
The most obvious/simplest issscanf:
```
if (sscanf(buffer, "%d%d%d", &v1, &v2, &v3) == 3) {
/* extracted 3 numbers successfully */
```
The%dformat specifier skips whitespace (which include\tand\ncharacters), so the variable extra stuff doesn't matter. It will also skip spaces, which may or may not be what you w... |
I need to read in unsigned char * bytes which are in reverse order to the native order. At the moment I have lots of little routines along the following lines:
```
uint8_t * bytes;
uint32_t r;
bytes = pt;
r = (((((bytes[0] << 8) + bytes[1]) << 8) + bytes[2]) << 8) + bytes[3];
pt += 4;
return r;
```
Is there a standa... |
The socket library for your platform provides the following functions which do these conversions:
ntohs- Network to Host Short (16-bit)htons- Host to Network Short (16-bit)ntohl- Network to Host Long (32-bit)htonl- Host to Network Long (32-bit)
To implement your code above, you can:
```
r = ntohl(*(uint32_t *)bytes... |
I need to check string values and if a string with value 0d0a in hex comes i need to break while loop.
How to check this since those are unprintable characters ?
|
To check if a string consists of just those two characters:
```
if ( 0 == strcmp(my_string, "\x0d\x0a") )
{
// action to take if it matches
}
```
If your intent is to look for CR-NL pairs then"\r\n"is equivalent (in ASCII encoding) and documents that a bit more clearly.
|
Hello my question is how to add specific path to avr-gcc. When I use:
```
#include <LiquidCrystal.h>
```
output is:
```
fatal error: LiquidCrystal.h: No such file or directory
```
when I use direct path:
```
#include "/usr/share/arduino/libraries/LiquidCrystal/LiquidCrystal.h"
```
Output is:
```
/usr/share/ardu... |
Copy all the header files from LiquidCrystal in /usr/include. Then use
```
#include <LiquidCrystal.h>
```
This will work.
|
I am using 64 bit gcc compiler on a intel machine to compile following code
```
void main(void) {
unsigned long L = 1, R = "123";
printf("%s %lu %lu", "1st",L, R);
printf("%s %d %s", "2nd", L, R);
}
```
I get following output
1st, 1, 42059132nd, 1, 123
my confusion is that when I take %lu what is this ... |
The reason that123gets printed correctly is a coincidence: it happens that in your architecture an address can fit intounsigned long. This is by no means a guarantee, so what you see is undefined behavior that simply "went your way".
The standard defines an integral typeuintptr_tthat is guaranteed to be capable of ho... |
This code looks like it is supposed to reverse the string , but instead it reverses only the first character and the output is :- delloworlh
Any ideas why this is happening
```
int main()
{
char p[] = "helloworld";
char t;
int i, j;
for(i=0,j=(strlen(p)-1); i<j; i++)
{
t = p[i];
... |
In your loop, you use the condition:i<jSo, after i reaches j/2, it starts to fix the reverse string again back to its original form.So you must change your condition toi<j/2+1;
|
i'm trying to understand why this code give me a segmentation fault!researchis a string and it's printing my tokens but after that i have a segmentation fault.Could you help me please ?
```
char buf[MAX_CHARS_PER_LINE];
strcpy(buf, research.c_str());
int n = 0;
const char * token[MAX_TOKENS_PER_LINE] = {};
for (n =... |
No pre-increment
```
if (!token[n]) break;
```
Always use strncpy when copying to a fixed length char array - not strcpy.
|
Which of these codes is appropriate and why ?
code1:
```
void fun(int *p)
{
*p=200;
}
main(){
int *i_ptr;
fun(i_ptr);
printf("%d", *i_ptr);
}
```
Code2:
```
void fun(int *p)
{
*p=200;
}
main(){
int i;
fun(&i);
printf("%d", i);
}
```
is it okay to pass pointer's address ?
|
You asked:
Which of these codes is appropriate and why ?
The first one will lead to undefined behavior sincei_ptrhas not been initialized to point to a valid memory.
You can change it to:
```
int main(){
int i;
int *i_ptr = &i;
fun(i_ptr);
printf("%d", *i_ptr);
}
```
and it will be OK.
BTW, I also ad... |
String of 3 numbers of any length - embedded in spaces and tabs, represented below with the\tmarker:
```
123456789 \t 12345 \t6789\n
```
There can be any amount and combination of space and tab' between the numbers.
For example, this is also valid:
```
1 \t \t2\t\t\t\t\t \n3\n
```
What is the most efficient wa... |
The most obvious/simplest issscanf:
```
if (sscanf(buffer, "%d%d%d", &v1, &v2, &v3) == 3) {
/* extracted 3 numbers successfully */
```
The%dformat specifier skips whitespace (which include\tand\ncharacters), so the variable extra stuff doesn't matter. It will also skip spaces, which may or may not be what you w... |
I need to read in unsigned char * bytes which are in reverse order to the native order. At the moment I have lots of little routines along the following lines:
```
uint8_t * bytes;
uint32_t r;
bytes = pt;
r = (((((bytes[0] << 8) + bytes[1]) << 8) + bytes[2]) << 8) + bytes[3];
pt += 4;
return r;
```
Is there a standa... |
The socket library for your platform provides the following functions which do these conversions:
ntohs- Network to Host Short (16-bit)htons- Host to Network Short (16-bit)ntohl- Network to Host Long (32-bit)htonl- Host to Network Long (32-bit)
To implement your code above, you can:
```
r = ntohl(*(uint32_t *)bytes... |
I need to check string values and if a string with value 0d0a in hex comes i need to break while loop.
How to check this since those are unprintable characters ?
|
To check if a string consists of just those two characters:
```
if ( 0 == strcmp(my_string, "\x0d\x0a") )
{
// action to take if it matches
}
```
If your intent is to look for CR-NL pairs then"\r\n"is equivalent (in ASCII encoding) and documents that a bit more clearly.
|
Hello my question is how to add specific path to avr-gcc. When I use:
```
#include <LiquidCrystal.h>
```
output is:
```
fatal error: LiquidCrystal.h: No such file or directory
```
when I use direct path:
```
#include "/usr/share/arduino/libraries/LiquidCrystal/LiquidCrystal.h"
```
Output is:
```
/usr/share/ardu... |
Copy all the header files from LiquidCrystal in /usr/include. Then use
```
#include <LiquidCrystal.h>
```
This will work.
|
String of 3 numbers of any length - embedded in spaces and tabs, represented below with the\tmarker:
```
123456789 \t 12345 \t6789\n
```
There can be any amount and combination of space and tab' between the numbers.
For example, this is also valid:
```
1 \t \t2\t\t\t\t\t \n3\n
```
What is the most efficient wa... |
The most obvious/simplest issscanf:
```
if (sscanf(buffer, "%d%d%d", &v1, &v2, &v3) == 3) {
/* extracted 3 numbers successfully */
```
The%dformat specifier skips whitespace (which include\tand\ncharacters), so the variable extra stuff doesn't matter. It will also skip spaces, which may or may not be what you w... |
I need to read in unsigned char * bytes which are in reverse order to the native order. At the moment I have lots of little routines along the following lines:
```
uint8_t * bytes;
uint32_t r;
bytes = pt;
r = (((((bytes[0] << 8) + bytes[1]) << 8) + bytes[2]) << 8) + bytes[3];
pt += 4;
return r;
```
Is there a standa... |
The socket library for your platform provides the following functions which do these conversions:
ntohs- Network to Host Short (16-bit)htons- Host to Network Short (16-bit)ntohl- Network to Host Long (32-bit)htonl- Host to Network Long (32-bit)
To implement your code above, you can:
```
r = ntohl(*(uint32_t *)bytes... |
I need to check string values and if a string with value 0d0a in hex comes i need to break while loop.
How to check this since those are unprintable characters ?
|
To check if a string consists of just those two characters:
```
if ( 0 == strcmp(my_string, "\x0d\x0a") )
{
// action to take if it matches
}
```
If your intent is to look for CR-NL pairs then"\r\n"is equivalent (in ASCII encoding) and documents that a bit more clearly.
|
Hello my question is how to add specific path to avr-gcc. When I use:
```
#include <LiquidCrystal.h>
```
output is:
```
fatal error: LiquidCrystal.h: No such file or directory
```
when I use direct path:
```
#include "/usr/share/arduino/libraries/LiquidCrystal/LiquidCrystal.h"
```
Output is:
```
/usr/share/ardu... |
Copy all the header files from LiquidCrystal in /usr/include. Then use
```
#include <LiquidCrystal.h>
```
This will work.
|
I would like to print a part of string. My program should print characters from begin until in string will be for example character like this: \"
For example:
```
char* text = "abcdef\"ghij";
```
And I would like to get:abcdef
I am not experienced in C so please help me in clear way.
|
Use*field width to select the number of characters to print:
```
#include <stdio.h>
#include <string.h>
char* text = "abcdef\"ghij";
printf("%.*s\n", (int) (strchr(text, '"') - text), text);
```
|
on changing this expression to postfix representation and then evaluating it.. I'm getting 17.8 as answer.. if "n" would have been of float type then there is no problem in answer. since n is a variable of integer type, digits after decimal oint should be truncated and answer should be 17 but the output is 15. how?
`... |
I'm getting 17.8 as answer.. if "n" would have been of float type then there is no problem in answer.
No. You can't. You will get17.833332if your expression would be
```
n=a*a*1.0/i+i/2.0*t+2+t;
```
See:
```
a*a/i = (4*4)/3 = 16/3 = 5
i/2*t = (3/2)*4.2 = 1*4.2 = 4.2
2 + t = 2 + 4.2 = 6.2
```
5 + 4.2 + 6.2 = 15.4... |
Basically,printfdoesn't produce output if I put it inmain().
This works:
```
#+begin_src C
printf("Hello World!\n");
#+end_src
```
But this
```
#+begin_src C
void main() {
printf("Hello World!\n");
}
#+end_src
```
results in
Code block produced no output
I have tried adding:results outputto thebegin_srcline. I ... |
Try this:
```
#+name: main
#+begin_src C
int main(int argc, char *argv[]) {
printf("Hello World!\n");
return 0;
}
#+end_src
```
|
This question already has answers here:declaration of variables with same name as global,local and static(5 answers)Closed9 years ago.
I have two variables, one which is local in a function and the other global. These two variables have the same name. During compilation, I have no errors. So when the code is running,... |
The local variable will always hide (shadow) the "global" one.
In Java, you can access to an instance variable by using the keywordthis. This is often used in constructors. For example:
```
private String someVar;
public ClassName(String someVar) {
this.someVar = someVar; // this.someVar is the instance variabl... |
I want to initialize a n*n square matrix to later pass it by reference into another function. But it doesn't even compile. I've tried everything, please help.
```
#include<stdlib.h>
int main()
{
int i, j, n = 3;
float **a;
a = malloc(n * sizeof (float **));//Here I try to create the n pointers to pointer ... |
you need to declare it like this :
```
float **a;
a = malloc(n * sizeof (float *)); // rows
for(i = 0;i < n;i++){
a[i] = malloc(n * sizeof(float)); // cols
}
```
|
```
int i = 1, j = 2, k;
k = i % ++j
```
I don't understand whykwould equal 1. I figured it what equal 0 because wouldn't the fraction 1/3 round down to 0? Thank you!
|
It's actually the remainder. Since three divided into 1 zero times, you have a remainder of one. 1 / 3(using integer arithmetic) is where you would expect the zero.
https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/what-is-modular-arithmeticshould be a good link
|
This question already has answers here:declaration of variables with same name as global,local and static(5 answers)Closed9 years ago.
I have two variables, one which is local in a function and the other global. These two variables have the same name. During compilation, I have no errors. So when the code is running,... |
The local variable will always hide (shadow) the "global" one.
In Java, you can access to an instance variable by using the keywordthis. This is often used in constructors. For example:
```
private String someVar;
public ClassName(String someVar) {
this.someVar = someVar; // this.someVar is the instance variabl... |
I want to make achar[1 048 576][16 384][1024]and aint [1 048 576][16 384]but I get an Error!
I want to make an 3d array as big as excel can handle!
|
to "make" an array in C you need to allocate some memory, either statically or dynamically with malloc.
In any case, the array will be mapped physically in your computer like in the RAM. So you need to have enough physical place to "make" it.
In your case, you want a char array of size:
1048576*16384*1024*sizeof(char... |
```
#include<stdio.h>
#include<stdlib.h>
int main()
{
int num1 = 15;
int num2 = 5;
int res
res = num1 + num2;
printf("Content of variable res: \n", var1);
system("pause");
return 0;
}
```
I tried compiling and running the program and it said error on
res = num1 + num2
|
You have a missing semi-colon:
```
int res
```
Do this:
```
int res;
//^--Missing
res = num1 + num2;
```
Or quite simply
```
int res = num1 + num2;
```
Also what in the world isvar1and also there is no format specifier inprintf(%dforint)
```
printf("Content of variable res: \n", var1);
... |
This question already has answers here:Undefined behavior and sequence points(5 answers)Closed9 years ago.
Specifically,here is my program on gcc.
```
#include <stdio.h>
char ga[]="abc";
void func(char ca[])
{
printf("%p %p %p %p\n",ca,&ca[0],&ca[1],++ca);
}
main()
{
func(ga);
printf("%p %p %p\n",ga,&... |
Change++catocaand you will get the expected results.It is not necessary that inprintf("%p %p %p %p\n",ca,&ca[0],&ca[1],++ca);, the arguments will be evaluated from left to right; such behaviour is compiler dependent.In this case, they are being evaluated from right to left; firstcais being incremented and then the pri... |
I'm learning C, I was looking athttps://github.com/mruby/mruby/blob/master/src/load.cand this line made me very confused:
```
mrb_irep* read_irep_record_1
```
On line 40.
I can see that this is a pointer of some sort.
What I'd like to know is the following
What does this do?
How do you use them?
What are these ca... |
That line is simply declaring a function that returns a pointer tomrb_irep. For example, what does a function declared asint foo()return? Well it returns anint, as we see in the declaration. Similarly, a function declared asmrb_irep* read_irep_record_1(...)returns a variable of typemreb_irep*, or a pointer to a struct... |
I want to make achar[1 048 576][16 384][1024]and aint [1 048 576][16 384]but I get an Error!
I want to make an 3d array as big as excel can handle!
|
to "make" an array in C you need to allocate some memory, either statically or dynamically with malloc.
In any case, the array will be mapped physically in your computer like in the RAM. So you need to have enough physical place to "make" it.
In your case, you want a char array of size:
1048576*16384*1024*sizeof(char... |
```
#include<stdio.h>
#include<stdlib.h>
int main()
{
int num1 = 15;
int num2 = 5;
int res
res = num1 + num2;
printf("Content of variable res: \n", var1);
system("pause");
return 0;
}
```
I tried compiling and running the program and it said error on
res = num1 + num2
|
You have a missing semi-colon:
```
int res
```
Do this:
```
int res;
//^--Missing
res = num1 + num2;
```
Or quite simply
```
int res = num1 + num2;
```
Also what in the world isvar1and also there is no format specifier inprintf(%dforint)
```
printf("Content of variable res: \n", var1);
... |
This question already has answers here:Undefined behavior and sequence points(5 answers)Closed9 years ago.
Specifically,here is my program on gcc.
```
#include <stdio.h>
char ga[]="abc";
void func(char ca[])
{
printf("%p %p %p %p\n",ca,&ca[0],&ca[1],++ca);
}
main()
{
func(ga);
printf("%p %p %p\n",ga,&... |
Change++catocaand you will get the expected results.It is not necessary that inprintf("%p %p %p %p\n",ca,&ca[0],&ca[1],++ca);, the arguments will be evaluated from left to right; such behaviour is compiler dependent.In this case, they are being evaluated from right to left; firstcais being incremented and then the pri... |
I'm learning C, I was looking athttps://github.com/mruby/mruby/blob/master/src/load.cand this line made me very confused:
```
mrb_irep* read_irep_record_1
```
On line 40.
I can see that this is a pointer of some sort.
What I'd like to know is the following
What does this do?
How do you use them?
What are these ca... |
That line is simply declaring a function that returns a pointer tomrb_irep. For example, what does a function declared asint foo()return? Well it returns anint, as we see in the declaration. Similarly, a function declared asmrb_irep* read_irep_record_1(...)returns a variable of typemreb_irep*, or a pointer to a struct... |
I have seen this countless of times. Instead of
```
#ifndef _common_h_
#define _common_h_
#endif /* _common_h_ */
```
people sometimes define their header files in following format:
```
#ifndef _common_h__479124197491641974591
#define _common_h__479124197491641974591
#endif /* _common_h__479124197491641974591 */
... |
The idea is to make it harder to trip yourinclude guardunintentionally, and/or to avoid triggering someone elses' include guards.
For example, if you are writing a library, and you have aCommon.hheader, then using_common_h_for the guard could prevent users of your library from having_common_h_guards in their own libr... |
This question already has answers here:Undefined behavior and sequence points(5 answers)Closed9 years ago.
Specifically,here is my program on gcc.
```
#include <stdio.h>
char ga[]="abc";
void func(char ca[])
{
printf("%p %p %p %p\n",ca,&ca[0],&ca[1],++ca);
}
main()
{
func(ga);
printf("%p %p %p\n",ga,&... |
Change++catocaand you will get the expected results.It is not necessary that inprintf("%p %p %p %p\n",ca,&ca[0],&ca[1],++ca);, the arguments will be evaluated from left to right; such behaviour is compiler dependent.In this case, they are being evaluated from right to left; firstcais being incremented and then the pri... |
I'm learning C, I was looking athttps://github.com/mruby/mruby/blob/master/src/load.cand this line made me very confused:
```
mrb_irep* read_irep_record_1
```
On line 40.
I can see that this is a pointer of some sort.
What I'd like to know is the following
What does this do?
How do you use them?
What are these ca... |
That line is simply declaring a function that returns a pointer tomrb_irep. For example, what does a function declared asint foo()return? Well it returns anint, as we see in the declaration. Similarly, a function declared asmrb_irep* read_irep_record_1(...)returns a variable of typemreb_irep*, or a pointer to a struct... |
I have seen this countless of times. Instead of
```
#ifndef _common_h_
#define _common_h_
#endif /* _common_h_ */
```
people sometimes define their header files in following format:
```
#ifndef _common_h__479124197491641974591
#define _common_h__479124197491641974591
#endif /* _common_h__479124197491641974591 */
... |
The idea is to make it harder to trip yourinclude guardunintentionally, and/or to avoid triggering someone elses' include guards.
For example, if you are writing a library, and you have aCommon.hheader, then using_common_h_for the guard could prevent users of your library from having_common_h_guards in their own libr... |
How to print prime numbers without using modulus(%)? I tried making an array of the prime numbers and checking whether the remainder was equal to 1. But later I realized that that was not possible:
```
int main()
{
for (int i = 2; i < num; i++)
{
if (num % i == 0) // without using % I am suppposed fin... |
```
int main()
{
for(int i=2;i<num;i++)
{
if((num-(num/i)*i)==0) // without using %
c++;
}
if(c==0)
printf("prime");
else
printf("not prime");
}
```
This should work.
|
Im trying to sort an array of string.If i remove the line
```
strcpy(a[j-1],a[j]);
```
terminal doesn't crash.
The array of strings is allocated this way in case that s the problem
```
array=(char **)malloc(sizeof(char *)*N);
for(i=0;i<N;i++)
array[i]=(char *)malloc(sizeof(char)*6);
```
Sort function... |
Make sure you allow an extra byte for the null terminator whenever working with character strings.
|
So I want to do something like this
```
#ifdef MYCOND
#define CR_BEGIN #pragma omp critical{
#define CR_END }
#else
#define CR_BEGIN
#define CR_END
#endif
```
GCC (4.8.2) does not like line 2 one bit, due to the hashtag. A related question here at SO gives the answer "use _Pragma("")" but it does not work in this ... |
You could do something like this:
start_critical.h:
```
#ifdef MYCOND
#pragma omp critical{
#endif
```
end_critical.h
```
#ifdef MYCOND
}
#endif
```
And then use it like this:
```
#include "start_critical.h"
//sometimes critical code here
#include "end_critical.h"
```
Since there are no header guards instart_cr... |
I'm using a 3rd party dll with no source code available. It runs perfectly fine, but every time I run my program, an annoying pop-up says "MyProgram.exe has triggered a breakpoint".
If I press continue, my program runs 100% correctly.
If I press break, I can see that the breakpoint is occurring in the 3rd party file ... |
I eventually checked in with the company that distributed the dll, and indeed there are breakpoints in there for reasons that I won't get into. However, if I run the program outside the debugger (even simply open the binary from windows), these popup windows do not occur.
Thank you all for your help!
|
I am trying to compile a mex file using openMp on win7_64. The file compiles fine, but when I try to run it I get the error:
```
Error: Invalid MEX file, the specified module could not be found
```
DependecyWalker tells me, that LIBGOMP_64-1.DLL is missing which I guess is the openmp library.
I installed the latest... |
I copied the LIBGOMP_64-1.DLL from the mingw/bin directory to the directory where the mex file is and now it works...
|
I'm trying to understand function which copies characters from stdin but I can't understand the while loop and the code following it exactly.....How does the while loop here work??
From what I understand it means untilithcharacter fromto[]isn't equal toithcharacter offrom[]keep on addingiam I correct??If yes than how ... |
Rewriting it might help:
```
do{
to[i] = from[i];
++i;
}while (from[i-1] != '\0') // -1 here because we incremented i in the line before and need to check the copied position
```
Do you understand now?
|
If I have the following:
```
int a = -10 && 0;
```
then does C evaluate-10as1because-10is different from0and then make
the comparation between1 && 0to get0as result?
Or does let-10and make the comparation as written?
Instead if I write:
```
int c = 10;
int b = 11;
int res = c > 10 && b == 11;
```
then the C make... |
The operator&&and||hasshort circuit behavior1. In
```
int a = -10 && 0;
```
since left operand is-10, which is non-zero and hencetrue, therefore right operand, i.e0is checked. In
```
int res = c > 10 && b == 11;
```
since left operand is evaluated tofalse, right operand is not evaluated.
1C11 6.5.13 (p4):If th... |
This is my little program:
```
#include <unistd.h>
#include <stdio.h>
int main() {
printf("1");
fork();
printf("2");
fork();
return 0;
}
```
The output of this code is12121212and I ask:Why does it print more than122?
|
Because printf is buffered and the text is printed only when program exits. Try to flush stdout after each print.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.