Issue I’m trying to parallelize some code using OpenMP (and MPI) using tasks. I have the following code: double t_copy = 0, t_forward = 0, t_backward = 0, t_diag = 0; void pc_ssor_poisson3d(int N, void *data, double *restrict Ax, double
Continue readingTag: c
error logging in c – linux environment
Issue I have been reading about how to keep error/warning logs of a C program on Linux environment. Is it better to write the errno to a file as it is done here or is it better to use syslog
Continue readingLongpolling with WinAPI's InternetReadFile()
Issue I’m writing a cross platform app. I need to get data from a longpoll url. On Mac/Linux I can use curl, curl_easy_perform() takes care of everything automatically. On Windows I have to use native api. The code below works
Continue readingHow to arrange the data of a .txt file for correspond with each value of the other data in C
Issue My problem is this I have a txt file name file.txt with the data. I need to input this for do some calculations,this how the code run: Please enter input file name file.txt File file.txt STUDENT NAME STUDENT NO.
Continue readingHow do I put my custom syntax highlighting in .vimrc?
Issue I use a shorthand form for the basic C/C++ types and I want Vim to syntax highlight them. I added syn keyword cType u8 s8 u16 s16 u32 s32 u64 s64 f32 f64 byte to my .vimrc, but that
Continue readingHow to change the syntax highlight color in GNU Enscript?
Issue GNU Enscript is a free replacement for Adobe enscript program, and I downloaded it for syntax highlighting and *.ps output, but can I change the default color model? I found that there is a file named c.st in /usr/share/enscript,
Continue readingNew and Delete Operator?
Issue What i’m asking now is, what does the delete and new operator do in C? I asked this question, when I was just simply thinking about how to allocate memory in C++, and I remembered you use the new
Continue readingTurn off vim syntax highlighting inside C++ comments
Issue I recently downloaded vim 8.0. I don’t know if I messed something up or a default changed, but in this code… int foo() { // This is a comment containing a “string” and the number 5. return 42; }
Continue readingHow to run command automatically for every new file opened in Vim
Issue I have to edit a bunch of files in a programming language that has C-like syntax (and which may or may not be used only within the confines of my university). To get syntax highlighting without going through the
Continue readingNano syntax highlighting in Mac OS X 10.7 (Lion)?
Issue How to enable syntax highlighting for nano in Mac OS X 10.7 (Lion)? According to what I found so far on Google is that it has got to do with /.nanorc file. I have no idea how to get
Continue readingOverride a function call in C
Issue I want to override certain function calls to various APIs for the sake of logging the calls, but I also might want to manipulate data before it is sent to the actual function. For example, say I use a
Continue readingIs it possible to override C syscall open without LD_PRELOAD?
Issue The source gets printed, but no open: or open64: gets printed. How to fix this? Thanks! /* gcc -o emload emload.c -ldl ./emload */ // emload.c #define _GNU_SOURCE #include <stdio.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <dlfcn.h> #include
Continue readingIs it possible to overload operators in C?
Issue Is it possible to overload operators (such as operators of comparison) in C? If so, how do you do it? I did a quick search, but all I found was for C++, and what I want is for C.
Continue readingSTB Image Writing JPEG Incorrectly
Issue i was working on my pixel art editor in C/C++ which was a fork of sixel till then saving the image as jpeg worked completely fine until i re-wrote my application to use SDL2 (so i don’t have to
Continue readingIs it safe to call a function after casting it to a void return type?
Issue I have a function that returns a value. Is it safe to cast it to a function pointer type that returns nothing (void) and then call it? Does the C standard give enough guarantees to make this safe on
Continue readingFunction pointer assignement and typecast
Issue I wanted to test a my idea about function pointers. I wrote a test but it doesn’t work(causes a Segmentation fault). Here is my test simplified: #include<stdlib.h> void a(){} void b(){} int main(){ size_t s=0; char* p1=(char*)&a; char* p2=(char*)&b;
Continue readingFunction pointer assignement and typecast
Issue I wanted to test a my idea about function pointers. I wrote a test but it doesn’t work(causes a Segmentation fault). Here is my test simplified: #include<stdlib.h> void a(){} void b(){} int main(){ size_t s=0; char* p1=(char*)&a; char* p2=(char*)&b;
Continue readingCasting struct into int
Issue Is there a clean way of casting a struct into an uint64_t or any other int, given that struct in <= to the sizeof int? The only thing I can think of is only an ‘ok’ solution – to
Continue readingEncoding QR data as PNG using C and stb_image_write
Issue im trying to render QR to image (png, svg) using QR-Code-generator-1.8.0 and stb_image_write, i follow the example on demo example and generate the QR correctly but very small and i dont know how to scale it, i suppose must
Continue readingC – extern, static, include
Issue Scoping in C is confusing as hell. I have a variable: “int qwe”. This var should be visible in one or more files – f1.c in this case, but not the another f2.c . Say i have: main.c, f1.c,
Continue readingScoping rules for struct variables in GCC
Issue Consider the following C program #include <stdio.h> typedef struct s { int x; } s_t; int main() { int x; s_t a; scanf(“%d”, &x); if (x > 0) { s_t a; a.x = x; } printf(“%d\n”, a.x); } The
Continue readingStatic scoping in C/C++
Issue In the following code, 2 is printed. int x = 1; int f(int y) { return x; } int main() { x = 2; printf(“%d”, f(0)); } How is it happening if we have static scoping in C? Why
Continue readingTrying to understand the difference between static and dynamic scoping in this C program
Issue So I am just trying to take a look at this little bit of code in C. Basically I am trying to learn how to read / determine the differences when using static and dynamic scoping and how the
Continue readingvariable set but not used Warning but also error undeclared identifier
Issue The debugger tells me I don’t use my variable but also that it is not declared. What is going on here? is an if statement it’s own scope? Somehow it seems to be the case that an array of
Continue readingCS50: Filter Edge Returns Mostly White Image
Issue I have been stuck on CS50 Filter – Edges for a few days now, having a hard time determining what’s wrong with my code. This code returns an almost all white images (which indicates to me final values are
Continue readingHow to get an image char array by using libpng?
Issue Although I have successfully utilized stb_image/CImg/lodepng open source to get a char array, the memory usage is too huge that I can’t implement it in a low power embedded system. Therefore, I try to use libpng to read a
Continue readingconverting bmp to 2d matrix messing up colors
Issue I’m trying to create a 2d array that contains RGB value for each pixel in the image, I created a copy of the original image to check out if the images are similar and I got that the output
Continue readingFast 7×7 2D Median Filter in C / C++
Issue I’m trying to convert the following code from matlab to c++ function data = process(data) data = medfilt2(data, [7 7], ‘symmetric’); mask = fspecial(‘gaussian’, [35 35], 12); data = imfilter(data, mask, ‘replicate’, ‘same’); maximum = max(data(:)); data = 1
Continue readingFunction to filter non digit characters in a string
Issue So I’m currently trying to create a function to filter out non digit characters but I can only use strlen. For example, "a4n55" -> "455" I’ve attempted it and I feel like I’m close. The printf’s are just for
Continue readingIs it possible to subscript into a uint64_t pointer in C?
Issue I’m a C beginner. Having trouble understanding whats happening with this code: #include <stdio.h> #include <stdint.h> int main(void) { uint64_t num = 99999; uint64_t *num_ptr = # uint8_t first_byte = ((uint8_t *)num_ptr)[0]; printf("%hhu", first_byte); return 0; } This prints
Continue readingAre there range operators in the C programming language?
Issue Are there range operators in C like there are in, say, Swift (closed range, open range)? For example, in a switch statement, in Swift I would write this: switch num { case 144…168: print("Something between 144 and 168") case
Continue readingProgram to find number of elements between two elements a and b (where a and b both are inclusive)
Issue Given an unsorted array of size n, write a program to find number of elements between two user-defined elements a and b (where a and b both are inclusive) of a user-defined array. Input : arr = [1, 2,
Continue readingGTK3 CCS style not being applied
Issue I am unable to set any style on a widget by name. Here is my code: #include <gtk/gtk.h> #define CSS_STYLE "\ #first { \ background-color: black; \ background-image: none; \ border-width: 0; \ color: yellow \ }" int main
Continue readingTrying to get 'Style' list for a GtkWidget
Issue I’m trying hard to get a list of style properties for a GtkWidget (GtkButton). This is my code so far: #include <gtk/gtk.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main (int argc, char *argv[]) { // Declare variables. GtkWidget
Continue readingHow to download a file from http using C?
Issue I spent the last days trying to figure out how to download a file from an URL. This is my first challenge with socket and I’m using it to have an understanding of protocols so I would like to
Continue readingWhat to use on Nodejs addons. Node.h or Napi.h
Issue I have some pretty simple questions. What is the main difference between node.h and napi.h. What should I use for normal/personal use case. Why are there more "nodejs" headers. (node.h, napi.h, nan.h, node_api.h, …) I have looked on Internet
Continue readingWhat to use on Nodejs addons. Node.h or Napi.h
Issue I have some pretty simple questions. What is the main difference between node.h and napi.h. What should I use for normal/personal use case. Why are there more "nodejs" headers. (node.h, napi.h, nan.h, node_api.h, …) I have looked on Internet
Continue readingWhat to use on Nodejs addons. Node.h or Napi.h
Issue I have some pretty simple questions. What is the main difference between node.h and napi.h. What should I use for normal/personal use case. Why are there more "nodejs" headers. (node.h, napi.h, nan.h, node_api.h, …) I have looked on Internet
Continue readingHow to download a file from http using C?
Issue I spent the last days trying to figure out how to download a file from an URL. This is my first challenge with socket and I’m using it to have an understanding of protocols so I would like to
Continue readingHow to download a file from http using C?
Issue I spent the last days trying to figure out how to download a file from an URL. This is my first challenge with socket and I’m using it to have an understanding of protocols so I would like to
Continue readingCommunication between multiple programs
Issue I am currently planning a complicated networking project on Windows IoT Enterprise. Basically, I will have a C program keeping alive a special network interface. This C program should receive tasks in some way from other programs on the
Continue reading