question
stringlengths
24
425
answer
stringlengths
5
405
``` unsigned int file = open(argv[1], O_RDONLY); printf("%u\n", file); printf("%u\n", elf.offset); lseek(file, elf.offset, SEEK_SET); printf("%u", file); ``` OutPut: ``` 3 52 3 ``` Shouldn'tfilebe set to52?
Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, shall be returned. try thisprintf("lseek_offset: %d\n", lseek(file, elf.offset, SEEK_SET));
This question already has answers here:What is the meaning of a dot (.) after an integer in c?(2 answers)Closed2 years ago. I read a code online and the next line caught my attention since I don't know why does it have a "." after the 0: ``` variable=0.; ``` I couldn't find the answer after looking for it. Could you please tell me what is the dot for? Thanks!!
The dot makes it adouble. A clearer way to write it is0.0.
As far as I know, ~0x00 equals to: First step, change 0's to 1 and 1's to zero, Second step, add 1 Step 1: 11111111111111111111111111111 (count =32) Step 2: 11111111111111111111111111111+1=0 Where am I doing wrong?
The~operator does not perform 2's complement negation. You can do that with the unary-operator (assuming your machine uses 2's complement representation). What~does is invert all bits. That's all it does, no adding 1.
As far as I know, ~0x00 equals to: First step, change 0's to 1 and 1's to zero, Second step, add 1 Step 1: 11111111111111111111111111111 (count =32) Step 2: 11111111111111111111111111111+1=0 Where am I doing wrong?
The~operator does not perform 2's complement negation. You can do that with the unary-operator (assuming your machine uses 2's complement representation). What~does is invert all bits. That's all it does, no adding 1.
When I use the following code I tried to replicate the idea thatsqrt(x)of something equalsX^(1/2) ``` pow(x, (1/2); ``` It returned 1 no matter what value I entered. I already solved this issue with the sqrt function but wanted to know why this is happening for the future.
In it's original form,1/2is integer division, producing a result of0. Math 101: Anything raised 0, is 1.
Within C how can I name a function? Just the name. typedef strlen StringLengthfails to compile with:strlen does not name a type.
A function pointer is a solution static Integer(*StringLength)(const Byte*) = strlen;
Why am I getting an error when using theatoi()function? ``` #include <stdio.h> #include <string.h> int main() { char s1[10], s2[10]; int x=5, y=6, z; sprintf(s1, "%d", x); sprintf(s2, "%d", y); strcat(s1, s2); z = atoi(s1); printf("%d, %s", z, s1); return 0; } ```
``` #include <stdlib.h> ``` Will fix it.
Here's my code: ``` #include <openssl/bio.h> int main (void) { BIO* bo = BIO_new(BIO_s_mem()); } ``` I'm compiling my code by doinggcc -lcrypto test.c. Any idea what's wrong?
You have the arguments in the wrong order, trygcc test.c -lcrypto Seewhy order matters
When I received packet withrecvat linux, is the kernel did de-fragmentation so I will get de-fragmentation data? Or should I take care of it on user-space?
When receiving UDP data via a socket of typeSOCK_DGRAM, you'll only receive the complete datagram (assuming your input buffer is large enough to receive it). Any IP fragmentation is handled transparently from userspace. If you're using raw sockets, then you need to handle defragmentation yourself.
When analyzing core on different machine, that binary was built for I ran into: ``` warning: .dynamic section for "/lib64/libc.so.6" is not at the expected address (wrong library or version mismatch?) ``` Is there a way to change which libc gdb is looking for?
Thanks to@Kevin Boone! set sysroothelped I set it to./and put desired libc in./lib64and then loaded core usingcore-file
I use theMin-GW GCC compileronWindows 10. Every time I compile, I need to make a.exeand then run it. Could there be any way to do the whole thing in one step?
You can combine commands in windows like you do on linux or macos! ``` gcc compilefile && c:/executefile.exe ``` (you need to replace that stuff with min-gw and your exe path) links: How do I run two commands in one line in Windows CMD?How to run an executable in Windows Terminal?
When analyzing core on different machine, that binary was built for I ran into: ``` warning: .dynamic section for "/lib64/libc.so.6" is not at the expected address (wrong library or version mismatch?) ``` Is there a way to change which libc gdb is looking for?
Thanks to@Kevin Boone! set sysroothelped I set it to./and put desired libc in./lib64and then loaded core usingcore-file
I use theMin-GW GCC compileronWindows 10. Every time I compile, I need to make a.exeand then run it. Could there be any way to do the whole thing in one step?
You can combine commands in windows like you do on linux or macos! ``` gcc compilefile && c:/executefile.exe ``` (you need to replace that stuff with min-gw and your exe path) links: How do I run two commands in one line in Windows CMD?How to run an executable in Windows Terminal?
Let's say I have aforloop and an array of ints. In myforloop, I sayif (array[i] == 2)then I want to skip all the rest of theforloop and go to the next instance. now I can't use thebreakkeyword as that will exit out of the entire loop. What can I use to exit out of only one instance?
You have to use continue to go to the next iteration: ``` if (array[i] == 2) continue; ```
Let's say I have aforloop and an array of ints. In myforloop, I sayif (array[i] == 2)then I want to skip all the rest of theforloop and go to the next instance. now I can't use thebreakkeyword as that will exit out of the entire loop. What can I use to exit out of only one instance?
You have to use continue to go to the next iteration: ``` if (array[i] == 2) continue; ```
Imagine I have a struct for a linked list: ``` struct node{ int data; struct node* next; struct node* prev; }; ``` I free the last node; does thenextpointer of the node before it becomeNULLautomatically? Because I noticed I didn't do it in a program but everything runs fine..
No. As for why your program appeared to run OK even if you forgot to reset a pointer, it could be you just got lucky.
Can anyone explain how does this work the output is A3 but how come it print 3 ``` #include <stdio.h> int main() { int i; if(printf("A")) i=3; else i=5; printf("%d",i); } ```
printf()returns the number of characters upon success and negative values on failure. Therefore, ifprintf("A")succeeds, it will return1. In C, values other than0is treated as true, soi=3;is executed.
I want to print my string which is "Something"without the first N lettersinside theprintfstatement. Example 1: I can do the "opposite" (printfjust N first letters): ``` #include <stdio.h> int main() { char str[] = "Something"; printf("%5s", str); } ``` Output:Somet Expected Output:hing
Start the printing in the middle: ``` printf("%s", &str[5]); ```
I have problem with NVIC registers in Keil. in my data sheet NVIC starts with NVIC_ISERx But in keil starts with ICTR register So I have problem with matching addresses
the order of the properties is not the same as the order in the peripheral. It is clearly visible here:
I would like to figure out the memory address of the following: ``` >>> ($rbp + $rdi*2 - 8) ``` And then once I have that value, inspect that memory address with: ``` >>> x/wx $address ``` How would I do this in gdb?
You can type this in directly after thep(rint) command. For example: ``` >>> p/x ($rbp + $rdi*2 -8) $2 = 0x7fffffffe43e >>> x/hx $ 0x7fffffffe43e: 0x001b # 27 ``` The$symbol stores the last value.
I would like to figure out the memory address of the following: ``` >>> ($rbp + $rdi*2 - 8) ``` And then once I have that value, inspect that memory address with: ``` >>> x/wx $address ``` How would I do this in gdb?
You can type this in directly after thep(rint) command. For example: ``` >>> p/x ($rbp + $rdi*2 -8) $2 = 0x7fffffffe43e >>> x/hx $ 0x7fffffffe43e: 0x001b # 27 ``` The$symbol stores the last value.
Does C have a#include<bitset>similar to C++ ? I have been looking for the past week. I can't find a equivalent directive preprocessor!
No, it does not. There are, however, ways to implement what you are looking for (or at least some sort of approximation). Take look at:http://c-faq.com/misc/bitsets.html- I think it is going to be useful.
I want to scan a value, and print the value that was scanned ``` int main() { int n; printf("enter value: "); n = scanf("%d",&n); printf("%d",n); return 0; } ``` however, the printed result gave me 1 instead of 9 as shown below. Why is this so and how do i solve this?
Becausenget override by the return value of scanf Just usescanf("%d", &n);if you don't want the number of parsed items assigned ton.
I want to scan a value, and print the value that was scanned ``` int main() { int n; printf("enter value: "); n = scanf("%d",&n); printf("%d",n); return 0; } ``` however, the printed result gave me 1 instead of 9 as shown below. Why is this so and how do i solve this?
Becausenget override by the return value of scanf Just usescanf("%d", &n);if you don't want the number of parsed items assigned ton.
This question already has answers here:Why is the gets function so dangerous that it should not be used?(13 answers)Closed3 years ago. Why is implicit declaration of gets() not allowed in C99?I had referred this question, which was how I came to know about it's deprecation.
Yes, you should usefgets()instead.
This question already has answers here:Why is the gets function so dangerous that it should not be used?(13 answers)Closed3 years ago. Why is implicit declaration of gets() not allowed in C99?I had referred this question, which was how I came to know about it's deprecation.
Yes, you should usefgets()instead.
I'm trying to make changes and compile open source 3d printers firmware in eclipse. Added all the project related to firmware but it showing symbol could not be resolved error. The cause of error is IDE cannot find the symbols. How can I solve this. It's compiling properly and also working on board.
Found the solution in indexer of the eclipse used active configuration settings and it solved all the Indexer error. Thanks for the help guys.
I'm trying to make changes and compile open source 3d printers firmware in eclipse. Added all the project related to firmware but it showing symbol could not be resolved error. The cause of error is IDE cannot find the symbols. How can I solve this. It's compiling properly and also working on board.
Found the solution in indexer of the eclipse used active configuration settings and it solved all the Indexer error. Thanks for the help guys.
How would I simplify all of this into one line? ``` REG &= ~BITA; REG &= ~BITB; REG &= ~BITC; REG &= ~BITD; REG &= ~BITE; ```
You can use|(bitwise or) operator. ``` REG &= ~(BITA | BITB | BITC | BITD | BITE); ```
Because FILE struct is depended on implementation, is there any fail-proof way to resolve FILE "object" to the path of the file it was create with?
It seems it is either hard due toFILEstructure being implementation dependent, or a sign of improperly designed code. As it stands now,stdlibdoes not provide any way of checking this exact thing. There are ways to check file handles, but those are system dependent and are not practical.
How does one definecopyanddeepcopymethods for a Python type defined in a C extension? Looking at thedocumentation, there doesn't appear to be atp_slot for these methods.
There's no slot. You just define the same methods you'd define in Python, but in C. (Typically, that means implementing__reduce__and getting the default__reduce__-basedcopy.copyandcopy.deepcopybehavior, but you can also implement__copy__and__deepcopy__if you want.)
i'm having process id from Task manager, i need to get the process name (complete with extension) from it. is it possible? i checked other questions, they are mostly command based.
Do you mean 'get the .exe filename by process ID' from C code? If so, you may have interesting inOpenProcess()and followingGetModuleFileNameEx(). Don't forget toCloseHandle()after you get the exe filename. :)
i'm having process id from Task manager, i need to get the process name (complete with extension) from it. is it possible? i checked other questions, they are mostly command based.
Do you mean 'get the .exe filename by process ID' from C code? If so, you may have interesting inOpenProcess()and followingGetModuleFileNameEx(). Don't forget toCloseHandle()after you get the exe filename. :)
I used a C / C++ code from the Internet, but my IDE gives me the following error on macos: ``` Use of undeclared identifier cfmakeraw ``` I now face the question, whether cfmakeraw is available on Macos / Unix ? Thank you 🙏
On your Mac, fire up Terminal and runman cfmakeraw. ``` SYNOPSIS #include &lttermios.h> void cfmakeraw(struct termios *termios_p); ``` So it is available, but you must include<termios.h>.
I am looking for a way to set a background image in gtk + 3 with c language , I already search and all the answer are for other languages or don't work anymore . Does anyone know a proper way to do it ?
For all problem encounter with the style in gtk i realize that using css for gtk wase the best answer , here some link that can be good to know Css + Gtk Overview Gtk + Css Properties
I used a C / C++ code from the Internet, but my IDE gives me the following error on macos: ``` Use of undeclared identifier cfmakeraw ``` I now face the question, whether cfmakeraw is available on Macos / Unix ? Thank you 🙏
On your Mac, fire up Terminal and runman cfmakeraw. ``` SYNOPSIS #include &lttermios.h> void cfmakeraw(struct termios *termios_p); ``` So it is available, but you must include<termios.h>.
I am looking for a way to set a background image in gtk + 3 with c language , I already search and all the answer are for other languages or don't work anymore . Does anyone know a proper way to do it ?
For all problem encounter with the style in gtk i realize that using css for gtk wase the best answer , here some link that can be good to know Css + Gtk Overview Gtk + Css Properties
I wrote this code in Sublime: ``` int main (int argc, char **argv) { printf("Hello World"); return 0; } ``` Saved it atC:\cygwin64\home\userashelloworld.c. Typed in this on Cygwin64 Terminal:$ gcc -o helloworld helloworld.c But I'm not seeing any output.Please help.
The windows executable can be obtained by:$ ./helloworld
I am trying to get the contents of my adc register for debugging but I don't know how to print it with gdb. If the address register offset is0x08would I usep/x *0x08? I am getting a result but it is 64 bits and I'm expecting 32. Thanks.
Turns out I was trying to find the wrong address and using a confusing hex to binary converter. Thanks to @Eugene Sh. for helping.
I am trying to get the contents of my adc register for debugging but I don't know how to print it with gdb. If the address register offset is0x08would I usep/x *0x08? I am getting a result but it is 64 bits and I'm expecting 32. Thanks.
Turns out I was trying to find the wrong address and using a confusing hex to binary converter. Thanks to @Eugene Sh. for helping.
I have the following code snippet for a PIC controller: ``` void __interrupt() ISR(void { // do some stuff } ``` when I use PC-Lint I always get the error message: Error 10: Expecting identifier or other declarator What can I do to handle the interrupt in PC-Lint?
You can define a dummy preprocessor macro by using the option-d__interrupt()=
I foundthis example; here the two threads threadDefault and threadCustomized are terminated by using pthread_exit followed by return. Why did the author write both instructions?
Mohith Reddy's answer is correct but misses the point. Of course the return statement is never executed sincepthread_exitdoesn't return, but it's there to suppress warnings from the compiler in case it's not aware thatpthread_exitdoesn't return.
I'd like to know where the function__cpuid_countis on osx. I'm assuming that it's inlibcbut running: ``` nm -g /usr/lib/libc.dylib ``` or ``` nm -g /usr/lib/libSystem.B.dylib ``` Does not list the function in the outputs. Is there a better way to locate where it is?
You can't find a__cpuid_countfunction because there isn't one. It's defined as a macro that expands to inline assembly incpuid.h.
What is the difference between this: ``` int num = 5; int* num1 = &num; printf("%p", num1); ``` and this: ``` int num = 5; int* num1 = &num; printf("%p", &num1); ```
In the first case,printf("%p", num1);, you're printing the value ofnum1, which is the address ofnum. In the second case,printf("%p", &num1);, you're printing the address ofnum1.
In C, a directory is created like this: ``` mkdir("hello"); ``` but what if we don't know the name of this directory (or it's told by user)? How can we define it to a computer? (%s is not working)
I would recommend you to usesnprintfso you can take any type of input. ``` #include <stdio.h> int main() { char name[50]; int i = 5; snprintf(name, 50, "dir.%i", 5); mkdir(name, 0700); } ```
I know thatPythonis platform independent, but I don't understand how that works forCPython. If the interpreter and some of the modules are written inC, aren't those going to be platform dependent?
C is platform independent in the sense that it can be compiled for any machine for which a compiler is made to target that machine. That's why the Python source code is platform independent, even if a Python binary can only work on one platform.
Why *pointer is an integer but not the string content "Hello from pointer" Thanks! ``` int main(void) { char *pointer; pointer = "Hello from pointer"; printf("*pointer is %d\n", *pointer); printf("\n"); } ``` the output is *pointer is 72
It's because the ASCII code for'H'(which is the first element of the array) is72. It is completely normal. Here is the ASCII Code table
``` #define len(a) if (a == 8) 1 \ else if (a == 3) 0 \ else -1 ``` this code is just an example how do we use nested if else. I don't want to use ternary operator as in that case i can't use else if statement.
Don't abuse the preprocessor. Use a real function: ``` constexpr auto len(int const a) { if (a == 8) return 1; if (a == 3) return 0; return -1; } ```
I had tried running a program which I solved in codeblocks and using math.h library in cs50 ide by Harvard University(which is Ubuntu based). Its giving me an error that library is not included. How to include to my cs50 ide..?
Are you including it in the compiling? Easiest way to do it is to compile with: make filename If that doesn't work check you are adding it correctly: #include
I am trying to write Python C extensions and I'm on a mac. I know how to install thePython.hheader file on Linux, but I don't know how to do it on a Mac. How can I install it?
The Python header file is a framework on Mac. You have to include it like this: ``` #include <Python/Python.h> ```
Is there a function to stretch an image's points to coordinates on the screen based on it's four points? If not, is there a way I could do that using math?
I mean something like a generalized texture-mapped quad. SDL_RenderGeometry()/SDL_RenderGeometryRaw()were added inSDL 2.0.18.
can someone please convert this line: strcpy_s(this->name, SIZE_NAME, d.getName()); to a strcpy function instead of strcpy_s? thank you
``` strcpy(this->name, d.getName()); ``` That was easy
I found this structure in the slides of my professor: ``` struct point{ int x; int y; } p; ``` What does p mean? So far I used only the classical struct like this: ``` struct point{ int x; int y; }; ```
``` struct point{ int x; int y; } p; ``` defines a variablepof typestruct point it is same as ``` struct point{ int x; int y; }; struct point p; ```
If I have the follow code " *k != (Queue *)0 * ", there is a violation of the rule 11.9. But why ? Qich can I rewrite thise code for make it compliant to MISRA 11.9?
You have to use the Keyword "NULL" to make it compliant: ``` *k != NULL ```
Can anyone explain the meaning of the code and give an example how to use it? I can understandfoo[100], but notbar. ``` typedef struct{ int a,b; } CELL, *PCELL; CELL foo[100]; PCELL bar(int x, CELL y); ```
``` PCELL bar(int x, CELL y); ``` is a function declaration. It means thatbarwill take in anintand aCELLas parameters, and it will return a pointer to aCELLas a return value. The actual body of the function will be defined later.
I'm writing a header file in C and needstdlib.hfor it to work. But, when I check if_STDLIB_His defined, the pre-processor says it's not, even if I include the file. I have tried it on multiple compilers, where it works on most but not ontdm-gcc. How can I fix this?
Looking atstdlib.hsource code, it seems like the macro to look for in tdm-gcc might be_TR1_STDLIB_H.So you can try something like: ``` #if defined _STDLIB_H || defined _TR1_STDLIB_H ```
I'm writing a header file in C and needstdlib.hfor it to work. But, when I check if_STDLIB_His defined, the pre-processor says it's not, even if I include the file. I have tried it on multiple compilers, where it works on most but not ontdm-gcc. How can I fix this?
Looking atstdlib.hsource code, it seems like the macro to look for in tdm-gcc might be_TR1_STDLIB_H.So you can try something like: ``` #if defined _STDLIB_H || defined _TR1_STDLIB_H ```
i know that -> is a pointer |= is OR. what is the logical meaning of such line? TIMER0->ROUTELOC0 |= TIMER_ROUTELOC0_CC0LOC_LOC15
|= does not mean OR. | means OR. |= is similar to +=, that is A |= B is the equivalent of A = A | B So to answer your question: It looks likeTIMER0is a structure with a memberROUTELOC0. The above expression is setting theROUTELOC0as the result whenROUTELOC0is ORed withTIMER_ROUTELOC0_CC0LOC_LOC15
Question 3 onCareer Ridesuggests that*(x+i)is the same as&x[i]. Can someone please explain whether this is correct?
That answer is incorrect. Given a pointer variablexand an integer variablei,*(x + i)is the same asx[i]andx + iis the same as&x[i]. It looks like they took half from each side of that for their answer, but they didn't provide any explanation, so we'll never know.
When I try to compile my code, I am getting a c statement with no effect warning: I am trying to use the bitwise operation to shift a value to the left. This is the code I am trying to do: ``` *bits << 5 ``` bits is a unsigned pointer.
You are calculating a value, but not assigning it to anything. You probably want to do this instead: ``` *bits <<= 5; // or equivalent *bits = *bits << 5; ```
Question 3 onCareer Ridesuggests that*(x+i)is the same as&x[i]. Can someone please explain whether this is correct?
That answer is incorrect. Given a pointer variablexand an integer variablei,*(x + i)is the same asx[i]andx + iis the same as&x[i]. It looks like they took half from each side of that for their answer, but they didn't provide any explanation, so we'll never know.
When I try to compile my code, I am getting a c statement with no effect warning: I am trying to use the bitwise operation to shift a value to the left. This is the code I am trying to do: ``` *bits << 5 ``` bits is a unsigned pointer.
You are calculating a value, but not assigning it to anything. You probably want to do this instead: ``` *bits <<= 5; // or equivalent *bits = *bits << 5; ```
A void function does not return any value as output and can take input values. The function below seems a void function, but there is the operator *, why? ``` void *function(){ printf("hello") } ```
That is not avoidfunction. That is a function that returns avoid*(pointer). But it seems incomplete, because theprintf()has no semicolon;and the function does not actually return avoid*.
A void function does not return any value as output and can take input values. The function below seems a void function, but there is the operator *, why? ``` void *function(){ printf("hello") } ```
That is not avoidfunction. That is a function that returns avoid*(pointer). But it seems incomplete, because theprintf()has no semicolon;and the function does not actually return avoid*.
I am currently working on a simulation using OpenMP. Whenever I try to execute with --trace to get the trace of the execution I get the following error ``` src/trace_graphics.c:5:10: fatal error: fut.h: No such file or directory 5 | #include <fut.h> ``` I redownloaded easypap but the file doesn't seem to come with it.
I friend of mine found the solution so I'm posting it ``` sudo apt-get install libfxt-dev ``` This will do the trick
what is the meaning of "D type qualifier is meaningless on cast type at this line of code" ``` (*((volatile RCC_t * const)0x400FE060)).USESYSDIV = 1; ``` and how to solve it?
volatile RCC_t * constsays the pointer (not the thing it points to) isconst. But this is for avalue, which is just a result used in an expression. Qualifiers likeconstare properties ofobjectsin memory. So it serves no purpose in this cast.
I need to get the size of a C/C++ executable at runtime in code. Unfortunately I cannot use /proc/self/exe as it's restricted on the target system.
Actually, it's a lot simpler than my attempt in the comments. The executable is simply: ``` (const char *)getauxval(AT_EXECFN) ``` That said, you should always try to open/proc/self/exefirst since the executable may have been deleted/moved/replaced while running.
While readinguname.c(in order to recreate it) I found a variable calledHOST_OPERATING_SYSTEM(line 371). It's never mentioned in the same file (as Strg+f told me) and not in the dependencies ofuname.c, as far as I could see. Where is the variable initialized and how to access it?
HOST_OPERATING_SYSTEMis defined at build time using autoconf modules defined ingnulib.
How can I determine the maximum file path length allowed in the system my program is running on? Is it inlimits.h? because I didn't find it there.
It should be NAME_MAX defined in<limits.h> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
How can I determine the maximum file path length allowed in the system my program is running on? Is it inlimits.h? because I didn't find it there.
It should be NAME_MAX defined in<limits.h> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
I know for sure there is a command for CUP that prints out the produced parse tree. Is there a similar command for Bison?
No, there isn't. If you want an AST or parse tree, you are responsible for building it, and the AST node objects should be able to print themselves out, as it were.
I know for sure there is a command for CUP that prints out the produced parse tree. Is there a similar command for Bison?
No, there isn't. If you want an AST or parse tree, you are responsible for building it, and the AST node objects should be able to print themselves out, as it were.
I'm running Debian on an x86_64 Intel processor. gcc (Debian 8.3.0) compiles the following program ``` #include <stdio.h> #include <stdalign.h> #include <stddef.h> int main(){ printf("%zd\n",alignof(max_align_t)); } ``` and outputs ``` 16 ``` What datatype requires a 16 byte alignment?
On x86_64,_Alignof(long double)==16.
I am getting core dump by this little programm. ``` #include <dirent.h> int main(void) { printf("process n%s",(long)getpid()); exit(0); } ``` can you explain me why?
You need to know where your functions come from, what they're returning and how to print the return value. ``` #include <unistd.h> #include <stdio.h> int main(void) { printf("process n%ld", (long)getpid()); } ```
I was wondering whether clang's new amazing custom size (things like 13-bit int, or 70-bit int, etc.) will get added to gcc.
Well. C23 has finally implemented them as_BigInt
I was wondering whether clang's new amazing custom size (things like 13-bit int, or 70-bit int, etc.) will get added to gcc.
Well. C23 has finally implemented them as_BigInt
Is there any difference between ``` const int* ptr[5]; ``` and ``` const int (*ptr)[5]; ``` ? I am trying to point to a const 5*5 2D int array, but I am not sure of the best way to do it
``` const int* ptr[5]; ``` This is an array of five elements, each element is a pointer toconst int. ``` const int (*ptr)[5]; ``` This is a pointer to an array of five elements, each element is aconst int.
``` struct sigaction act; memset(&act,0,sizeof act); sigaction(SIGALRM, &act, NULL); alarm(any_seconds); ``` My alarm code in linux. I met "Alarm clock" message. But I don't want met this message. How can I do? please help.
You can catch the signal ``` static void alarmHandler(int signo) { (void)signo; printf("Another message\n"); // or skip this line } ... alarm(any_seconds); signal(SIGALRM, alarmHandler); ```
I declare double variables t and tau, and assign them values 1 and 0.00001 This line of code produces 536870912 in the console. What can be the reason? printf("%i\n",round(t/(tau*double(2)))); By the way, I write code in a C++ compiler, but practically it's C.
roundreturns adouble. Printing it with%iis undefined behaviour. Use%ffor printingdouble: ``` printf("%f\n",round(t/(tau*double(2)))); ```
About Leap Year algorithm, ``` if( (year%4==0 && year%100!=0) || (year%400==0)) ``` Why does it use "or" instead "and"year%400==0?
Are you sure about knowing the meaning of what leap year is?
About Leap Year algorithm, ``` if( (year%4==0 && year%100!=0) || (year%400==0)) ``` Why does it use "or" instead "and"year%400==0?
Are you sure about knowing the meaning of what leap year is?
In my c programming homework I am asked toinitialize an array using an initializer list delimited by braces.I've googled every thing and I can't find an example of an initializer list delimited by braces. By the way, the array I am initializing is 2-D so if you could format your answer so that it is representative of a 2-D array, that would be very helpful. Thanks
Here's an example: ``` int a[ 2 ][ 3 ] = { { 5, 6, 7 }, { 10, 20, 30 } }; ```
In my c programming homework I am asked toinitialize an array using an initializer list delimited by braces.I've googled every thing and I can't find an example of an initializer list delimited by braces. By the way, the array I am initializing is 2-D so if you could format your answer so that it is representative of a 2-D array, that would be very helpful. Thanks
Here's an example: ``` int a[ 2 ][ 3 ] = { { 5, 6, 7 }, { 10, 20, 30 } }; ```
I want to create a file on/dev/mmcblk0, if it doesn't exist already, and then write to it. My question is how to check if there is already such file on the sdcard and then access it, does it show up like/dev/mmcblk0/somefile?
/dev/mmcblk0points to a drive, so you will need to mount the drive first before you can see what files are available on it or create new files.
If we have a 32bit pattern of 1111 1111 1000 0000 0000 0000 0000 0000, which is -2^23 in int, when we convert int to float will this be -INF?
Conversions in C operate onvalues, and the value -2^23 is representable infloat, so the result of the conversion is the value -2^23.
I'm trying to use the raylib on Visual Studio 2019, I followedthis tutorialI can build without anywarning, but when I run my program a error windows saying that it can't find "raylib.dll" apear. What can I do to solve this ?
I solve my issue by placing the raylib.dll that's inthis raylib distributionin the folder where my executable is build
I got an assignment in which I can use any method, as long as it is part of the ANSI - c standard. I want to usefreopen, except I don't know if its part of the standard. I have looked at "The C programming language" book's list of methods and it doesn't seem to be there, but it was in C89 so I doubt it isn't in ANSI.
freopen()functionconforms to C89. And C89 isANSI C.
Hello I am a complete beginner in a university course for C programming. I am trying to compare 4 inputs for exact matches using strcmp. The code only take into account the first two though. Is it possible to compare two strcmp values to compare 4 inputs?
You can concatenate the results via&&. ``` if (strcmp(str1, str2) == 0 && strcmp(str1, str3) == 0 && strcmp(str1, str4) == 0) { printf("They match!") } ```
I have currently an issue with debugging with visual studio code . I want to attach GDB to a C (.so) shared library module that is called via a main python program that interfaces with the C shared library with F2PY. How do I procede to create a launch configuration in vscode for gdb to debug that C shared library?
Cross-language debugging from Python to C is only available in Visual Studio, not in VS Code.
``` for (unsigned i = 0; i < 3; i++) { if (i == 2) i = -1; } ``` I can't understand why this loop is infinite. I get that it wraps around wheni = -1but UINT_MAX is greater than 3.
If I rewrite your code, then might more clear to see why ``` unsigned i = 0; while (i < 3) { if (i == 2) i = -1; i++; } ``` i++happens at the end of the loop soibecame0again.
I want to search and replace a pointer ``` char* test ``` however, when I type ``` :%s/char* test/something/g ``` I get ``` E486: Pattern not found: char* test ``` I assume this is due to vim trying to use regex in search. How can i tackle this issue? Is it possible to replace such text?
You need to escape star symbol. This should work: ``` :%s/char\* test/something/g ```
``` for (unsigned i = 0; i < 3; i++) { if (i == 2) i = -1; } ``` I can't understand why this loop is infinite. I get that it wraps around wheni = -1but UINT_MAX is greater than 3.
If I rewrite your code, then might more clear to see why ``` unsigned i = 0; while (i < 3) { if (i == 2) i = -1; i++; } ``` i++happens at the end of the loop soibecame0again.
I want to search and replace a pointer ``` char* test ``` however, when I type ``` :%s/char* test/something/g ``` I get ``` E486: Pattern not found: char* test ``` I assume this is due to vim trying to use regex in search. How can i tackle this issue? Is it possible to replace such text?
You need to escape star symbol. This should work: ``` :%s/char\* test/something/g ```
How can I write following C expression using left-shift bit-wise operator (<<) and plus sign (+)? ``` y = x * 6; ```
x << nmeans x * 2nby definiton (C18 §6.5.7/4). Knowing that x * 6 means x * 2 + x * 4, which is x * 21+ x * 22, we can rewritey = x * 6;asy = (x << 1) + (x << 2);.
I just wrote a basic c program to run but compiler prompts the error (see attached image). I have installed Dev-C++ before where I did C++ Programming. But when I wrote C code it prompts error I have deleted it & reinstalled the Dev-C++ again but couldn't run please help. IDE Version: 5.11
You must choose the right Project configuration (C project): Remarque : you must have a project path without space. Exemple :C:\Ali\untiled\untiled.c
I just wrote a basic c program to run but compiler prompts the error (see attached image). I have installed Dev-C++ before where I did C++ Programming. But when I wrote C code it prompts error I have deleted it & reinstalled the Dev-C++ again but couldn't run please help. IDE Version: 5.11
You must choose the right Project configuration (C project): Remarque : you must have a project path without space. Exemple :C:\Ali\untiled\untiled.c
There is no re-negotiation in TLS1.3, will SSL_write yield SSL_ERROR_WANT_READ? And will SSL_read yield SSL_ERROR_WANT_WRITE? Here are openssl docs in SSL_write and SSL_read
I created an issue in github, and got the developer's answer. https://github.com/openssl/openssl/issues/11211#event-3094172350 In TLS1.3, SSL_write can yield SSL_ERROR_WANT_READ, and SSL_read also can yield SSL_ERROR_WANT_WRITE
What happens when you call read() (or recv()) on an open socket, and you specify a length that is more the number of bytes ready to be read in the buffer (TCP) or the length of the next datagram (UDP)?
In both cases, if the size of the buffer is larger than the amount of available data, what data is available is read and the number of bytes actually read are returned from the function. That return value is what you should use when operating on the data.
how to explain this right ``` char*(*a)(int, int); ``` just explain what does this declaration means. I'm not sure how to explain it right. Thank you very much!
ais a pointer to a function with two parameters of typeintthat returns achar*. The ``Clockwise/Spiral Rule'' cdecl: C gibberish ↔ English
This question already has answers here:How do I determine the size of my array in C?(25 answers)Closed3 years ago. For example a code like: ``` int arr[5] = {1, 2, 3, 4, 5} ``` Is there anyway to get the 5 in arr[5]? I haven't learnt C++ before.
You can get it by getting the array size and divide it by the size of a single element: ``` int arr[5] = {1, 2, 3, 4, 5}; size_t lengthOfArr = sizeof(arr)/sizeof(arr[0]) ; ```