Can you compare two constant pointers in the C preprocessor?
Stack Overflow » C#
by Edward Falk
3h ago
Say my code looks like this: gpios.h: #define GPIO_BASE 0x08000100 #define GPIOA ((GpioRegs *) (GPIO_BASE + 0x04)) #define GPIOB ((GpioRegs *) (GPIO_BASE + 0x0C)) #define GPIOC ((GpioRegs *) (GPIO_BASE + 0x14)) switches.h: #define SWITCH1_PORT GPIOA // On this particular system, both switches #define SWITCH2_PORT GPIOA // are on the same port. This could change in the future switches.c: #if SWITCH1_PORT == SWITCH2_PORT // Code is a lot simpler if both switches are on the same port #else // Otherwise do it the hard way #endif SWITCH1_PORT and SWITCH2_PORT are both constants at comp ..read more
Visit website
Why does Python from C crash on initialization?
Stack Overflow » C#
by user2731097
3h ago
PyObject *python_module; char *module_filename = "/mnt/USB3/C/Python_from_C/python_processes"; Py_Initialize(); python_module = PyImport_ImportModule(module_filename); if(python_module == NULL) { printf ( "Failed to load module \"%s\"\n", module_filename ); getchar(); } ` The python_processes.py file exists. The returned module is always NULL. The PyImport_ImportModule() function emits no error message, I have tried many Python initialization schemes (there are rather too many) and all result in the module not being loaded. Here is another attempt. This ..read more
Visit website
Relation of sigprocmask and pthread_sigmask for multithreaded program
Stack Overflow » C#
by Caulder
3h ago
sigprocmask(2) says: Each of the threads in a process has its own signal mask. , but also: The use of sigprocmask() is unspecified in a multithreaded process; see pthread_sigmask(3). pthread_sigmask(3) states, that: The pthread_sigmask() function is just like sigprocmask(2), with the difference that its use in multithreaded programs is explicitly specified by POSIX.1. Other differences are noted in this page. , but than there are no notes about that. However https://docs.oracle.com/cd/E19120-01/open.solaris/816-5137/gen-19/index.html says, that: The call to sigprocmask() in a multithrea ..read more
Visit website
SDL2 not throwing window close event
Stack Overflow » C#
by Hobbes
3h ago
For personal use, I'm coding an additional layer on SDL2, which includes an event manager. It correctly detects every type of event, except SDL_WINDOWEVENT_CLOSE. After trying to debug my code, I realized that SDL2 actually never fires that event on my device... So there's no problem when I have only 1 window (because SDL_QUIT is thrown instead), but when I have several windows I just can't detect when a window closing is requested, and I have to ctrl+C my program from the shell to have SDL_QUIT fired manually. Here is a minimal working example : #include <stdio.h> #include <SDL2/SDL ..read more
Visit website
Scanf not changing the value of a variable [closed]
Stack Overflow » C#
by ringojuice
3h ago
In an attempt to help learn C I've been trying to write a simple calculator, but I'm stuck on the issue of scanf not assigning the inputted value to a variable. I've seen people recommend fgets over scanf but that brought more issues so I decided to stick with scanf for now. the reason I have all the getchar(); and " %d\n" included in there is because the program would skip directly past those inputs otherwise. Thank you. #include <stdio.h> #include <string.h> int main() { int numberOne; int numberTwo; int result; char operation[8]; printf("Enter your first nu ..read more
Visit website
How to use the malloc() function in order to return an array?
Stack Overflow » C#
by NoobCoder
3h ago
I'm trying to solve this question: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Output: Because nums[0] + nums[1] == 9, we return [0, 1]. my code is: /** * Note: The returned array must be malloced, assume caller calls free(). */ int* twoSum(int* nums, int numsSize, int target, int* returnSize ..read more
Visit website
Why is SSE4.2 cmpstr slower than regular code?
Stack Overflow » C#
by nerowim
3h ago
I'm trying to validate a string that must only contain ASCII visible characters, white space and \t. But it seems that ASCII table lookups are faster than the _mm_cmpestri instruction with _SIDD_CMP_RANGES on most CPUs. I've tested it on an i5-2410M, an i7-3720QM, an i7-5600U and a KVM-virtualized Xeon of unknown type and only on the last one is the vectorized version faster. My test code is here: #include <stdio.h> #include <string.h> #include <inttypes.h> #include <sys/time.h> #include <sys/mman.h> #include <immintrin.h> #include <stdalign.h> #inclu ..read more
Visit website
What is the job of autogen.sh when building a c++ package on Linux [duplicate]
Stack Overflow » C#
by Elad Weiss
3h ago
I saw a common pattern when installing a C/C++ package from source on Linux (Ubuntu 16.04): ./autogen.sh ./configure make make install I understand make and make install, and I guess configure creates a Makefile based on user preferences, but I don't see why autogen.sh is necessary. Does anyone know what it is there for ..read more
Visit website
Programmatically check whether a linux kernel module exists or not at runtime
Stack Overflow » C#
by user237076
3h ago
I am writing a C daemon, which depends on the existence of two kernel modules in order to do its job. The program does not directly use these (or any other) modules. It only needs them to exist. Therefore, I would like to programmatically check whether these modules are already loaded or not, in order to warn the user at runtime. Before I start to do things like parsing /proc/modules or lsmod output, does a utility function already exist somewhere? Something like is_module_loaded(const char* name); I am pretty sure this has been asked before. However, I think I am missing the correct terms to ..read more
Visit website
C Library Compile Error
Stack Overflow » C#
by Icestorm
3h ago
I'm trying to compile the sorting library from http://www.yendor.com/programming/sort/ Direct Link to library: http://www.yendor.com/programming/sort/sort-all.tgz When I run make the compiler says: gcc -g -O -DCUTOFF=15 -c sorttest.c In file included from sorttest.c:15: sort.h:66: error: conflicting types for ‘heapsort’ /usr/include/stdlib.h:301: error: previous declaration of ‘heapsort’ was here make: *** [sorttest.o] Error 1 Can someone help with this issue ..read more
Visit website

Follow Stack Overflow » C# on FeedSpot

Continue with Google
Continue with Apple
OR