Questions tagged [c]
C is a general-purpose programming language used for system programming (OS and embedded), libraries, games, and cross-platform. This tag should be used with general questions concerning the C language, as defined in the ISO 9899 standard (the latest version, 9899:2018, unless otherwise specified — also tag version-specific requests with c89, c99, c11, etc.). C is distinct from C++, and it should not be combined with the C++ tag without a specific reason.
405,381
questions
1
vote
0
answers
20
views
Using previously set fields when initializing structure with compound literals
What is the expected behavior of referring to previously set fields, when declaring initial values for a struct using compound literal: Specifically is it ok to: struct foo v = { .v1 = ..., .v2 = .v1+...
0
votes
0
answers
19
views
Repeated short identical parallel jobs
I have an algorithm that requires many parallel reruns of the same code. The code is short and finishes in less than a microsecond. This will be run millions of times which creates some problems when ...
0
votes
0
answers
61
views
How to executing code before a process is launched?
I am currently working on a project where I need to execute some code before a certain process is launched.
I am not sure how to approach this problem and I was hoping someone could provide some ...
0
votes
3
answers
47
views
Why using else if instead of if here when building a binary tree?
When building the insertion function in binary tree, I use two if statement to track the node( if the value is smaller than the current node,go left;if bigger,go right) .
I know the difference between ...
0
votes
0
answers
14
views
undefined reference to `WinMain@16' : Mingw error while compiling
This is the problem code. Please help!!
#include<stdio.h>
int mainn()
{
printf("Hello World");
return 0;
}
Tried fixing from yt videos but they suggest to save the file ...
0
votes
0
answers
13
views
How to create a page aligned variable in a kernel module?
So I want to have a buffer in my kernel module that I created like that:
static char buf[BUF_LEN];
My problem is that the start address of this buffer is not necessarily page aligned. To give a bit ...
-3
votes
0
answers
34
views
Only the First Line of Output is Printed in C Program in VS Code on Windows Using MinGW
In C program only the first line of output is printed when I run the compiled executable. Despite the program compiling without errors, the subsequent lines do not appear.
Details:
Operating System: ...
0
votes
1
answer
23
views
FFmpeg C demo generates "Could not update timestamps for skipped samples" warning
When I run my demo code I get these warnings when testing it on a webm video:
[opus @ 0x5ec0fc1b4580] Could not update timestamps for skipped samples.
[opus @ 0x5ec0fc1b4580] Could not update ...
2
votes
1
answer
82
views
Finding repeating sequences with less than O(n^2) time complexity
Is it possible to find repeating sequences of any length (without complete overlaps) with a time complexity less than O(n^2) ?
For example, take a string like this:
...
0
votes
1
answer
55
views
Using free on nested structs makes program crash
I was recently exploring ll the oop features of C, when i came to this issue. I want to create a game engine with C, so i use nested structs to organize ewerything. But when freeing the memory, the ...
0
votes
2
answers
62
views
simple calculator program exiting unexpectedly after input (C, MinGW)
'm trying to write a basic calculator program in C using MinGW. However, the program exits unexpectedly after I enter the operator (+, -, *, or /). I've checked for common errors like missing return 0;...
-4
votes
0
answers
47
views
Objdump - how to produce source code for the library functions in the assembly output
When I use objdump with -S flag, it produces the source code aligned with the corresponding assembly code. For example:
I want similar source code information for the library functions included in ...
1
vote
0
answers
26
views
rspamd error: undefined reference to 'EVP_*'
I am trying to install rspamd, but am encountering the following error:
[ 90%] Linking CXX executable rspamd
librspamd-server.so: error: undefined reference to 'EVP_MD_get_size'
librspamd-server.so: ...
1
vote
0
answers
19
views
raspberrypi gpio interrupt rtems
I'm trying to develop an RTEMS application that decodes a message that's encoded with Manchester encoder transmitted by the transmitter board.
Two Raspberry Pi 2 are mounted on the board, which are ...
0
votes
0
answers
35
views
Error merging Arduino and C/C++ files in the same directory: Compilation issues and file access problems
i am a c developer and just shift to arduino and i'm getting error my code should just do nothing but perform a c operation and show the response on lcd
#include <stdio.h>
#include <stdlib.h&...
3
votes
0
answers
31
views
Measuring cache line latency
I want to measure the latency to access one element of a cache line.
I have an struct with a next index and padding to have a length of a cache line size (64 bytes in my arch).
Then, an array of N ...
1
vote
1
answer
46
views
How to implement functions within a UART Interrupt Handler?
I know this is an incredibly long questions but ive posted as much detail so I can give the most context and hopefully make it easier to answer.
I am currently creating a program to receive messages ...
1
vote
1
answer
20
views
Performance counter not running with perf_open_event()
I am trying to access the performance counters in a large and complex application. But when I read the result it always returns 0. I also enabled the total running time and the total enabled time, ...
3
votes
0
answers
79
views
Understanding the flow of the kernel upon receiving a SIGSEGV for null-dereference
I'm trying to figure out the sequence of things that occur inside the Linux kernel (x86_64, v6.9) when we write these two codes:
// Null-dereference + writing to page zero
*(char *)0 = 0;
// Null-...
1
vote
1
answer
60
views
Function implicitly returns the value left by printf
I have the following C code.
Now I know that functions having a return type of int will have implicit return type if there is no return statement. I also get that reading the implicit value is an ...
1
vote
2
answers
86
views
GCC compiler handles "char * str" and "char str[]" with the & operator differently
The compiler treats the types char * var and char var[] differently when it comes to taking the address of a variable via the & operator. Here's a little snippet of code to demonstrate:
#include &...
0
votes
3
answers
74
views
Why does changing a pointer type by casting not change the resulting pointer value?
If I cast a pointer from int32_t to int8_t, why does the pointer's value not change? I expected the resulting value to change from a 32-bit address to an 8-bit address.
When experimenting with the ...
1
vote
1
answer
54
views
Why does printf flush or not flush depending on where the line is in a loop?
Why, in this program, does the printf function print or not print depending on where it is inside the loop?
#include <stdio.h>
#include <time.h>
int main()
{
char frames[] = {'-',...
0
votes
1
answer
53
views
Can I run the Pthreads library directly on a virtual machine
So, I have installed a virtual machine (kali linux), I would like to know if I can complete my assignment, which requires multiple processes to be created and managed using Pthreads library in C. She ...
2
votes
0
answers
19
views
Why does GtkText's context menu (copy, paste) stop working; If css border is applied on GtkText?
I want to apply a border to GtkText Widget using css but facing issue. If I apply the border via CSS, the copy paste option in the default right click context menu stops working. Showing this warning -...
1
vote
0
answers
48
views
/usr/bin/ld multiple definition of during compile
I just want to mention that I didnt write this code or modify it in any way prior to trying to compile it. I have just been copying the source from EL5 to 6 to 7 and compiling it. I think when it went ...
0
votes
1
answer
56
views
Align array of structs within 4K boundary
I am trying to reformat some code that uses a struct aligned by a 4096 byte boundary. The struct is basically a 2d array at each point is 2 different uint16 with some padding at each row.
The way the ...
0
votes
0
answers
9
views
Is it some kind of numerical instability for this convolution product (C language)?
I am trying to program a convolution product function in C language.
I am generating sine waves with the following function:
int generate_sin_wave(signal_t *signal, sin_wave_config_t *wave_config, ...
0
votes
0
answers
13
views
Need capl script to get the value of particular byte of a first CAN message which is being sent periodically over CAN bus
Need CAPL script to get the value of particular byte of a first CAN message which is being sent periodically over CAN bus
I tried to set the local flag to some other value and added if condition to ...
0
votes
1
answer
23
views
How to open Audit Process Creation by coding?
enter image description here
Local Group Policy Editor->Local Computer Policy->Computer Configuration->Windows Settings->Security settings->Advanced Audit Policy Configuration->...
1
vote
0
answers
23
views
Why should I use portTICK_PERIOD_MS instead of pdMS_TO_TICKS?
I can retrieve the number of ticks needed to reach, say, 500 ms using either:
const TickType_t xDelay = 500 / portTICK_PERIOD_MS
or:
const TickType_t xDelay = pdMS_TO_TICKS(500);
where:
#define ...
1
vote
4
answers
100
views
Shouldn't this be considered a double pointer?
I'm a novice C programmer, and I have what is probably a simple question. I'm learning about using pointers to structs currently, and I can't understand why lines 20 or 22 below work. I understand ...
0
votes
2
answers
39
views
Using semaphores to print out a specific pattern
Given these methods:
void* thread1Func(void* p) {
while(1) {
printf("A ");
}
}
void* thread2Func(void* p) {
while(1) {
printf("B ");
}
}
void* ...
0
votes
0
answers
34
views
How to set the stack depth parameter when creating a task
In ESP-IDF you can create a task with the xTaskCreate() function:
static BaseType_t xTaskCreate(TaskFunction_t pvTaskCode, const char *constpcName, const uint32_t usStackDepth, void *constpvParameters,...
0
votes
1
answer
53
views
thread 1: BAD ACCESS, how to solve this?
When I run this short program I run in a BAD ACCESS error pretty every time I try to import data from the file, I'm asking what I got wrong and what I should do to fix it and to upgrade the program, I'...
1
vote
2
answers
86
views
What is a perfect example for the sentence "There is a sequence point immediately before a library function returns" in C11 standard?
As is well known, the sentence:
There is a sequence point immediately before a library function returns.
which comes from 7.1.4 p3 in the C11.
I have also seen in some posts some explanations of ...
2
votes
2
answers
69
views
How to optimize the code that finds the maximum sum of elements within a sub-rectangle (contiguous block) of a 2D array?
I have working code that finds the maximum sum of elements within a sub-rectangle of a 2D array. I'm wondering if there are any optimization techniques I could use to improve its performance.
The ...
0
votes
0
answers
56
views
In C, There is no buffer overflow in strings [duplicate]
Whenever we store data more than the memory allocated to variable we got some unexpected results.But I declare a character array (name) with size 5 and get value from the user (greater than 5 ...
-7
votes
0
answers
48
views
in vs code its note showing error squiggles [closed]
No semicolon and value in whlie(___) but no squigles
As u can i havent inserted semicolon and didnt insert any value in while(___) but it doesnt show any error.
i tried this 'enter image description ...
-1
votes
0
answers
35
views
I am not able to execute a C program in Vs code
Not able to execute a program in C in VSCode it is giving this error message
The terminal process failed to launch: Path to shell executable "c:\Users\manda\OneDrive\Desktop\gcc" does not ...
0
votes
1
answer
93
views
Is out-of-scope local variables' memory reused?
struct Big { char data[5000]; };
extern int some_input;
int main() {
switch (some_input) {
case 0: {
struct Big big;
big.data[0] = 0; // just try to do something
...
2
votes
0
answers
10
views
Problem opening xvid264 with avcodec_alloc_context(NULL)
I want to multiplex audio and video together using the ffmpeg encoding library with xvid264rgb codec. I can open the codec when I create the context specifying that codec, but not if I use NULL for ...
1
vote
1
answer
22
views
Using libavformat to create MKV Container and having VLC Playback Issues
When running the remuxing code against an MP4 as input and MKV as output, the media plays in VLC media player but the progress bar does not update. If I run...
ffmpeg -i input.mp4 -map 0 -c copy ...
-5
votes
0
answers
79
views
problem with else if statement not executing [closed]
I was practicing else if statement for a basic c course but this following part of the code isn't executing even though the syntax is correct (I'm using gedit in Ubuntu)
#include <stdio.h>
int ...
0
votes
1
answer
72
views
I am trying to understand 'restrict' keyword introduced in C99
So for the past week I tried to understand how restrict works, I have a few suspisions on how it works and I just want to make sure that I am at least correct in the assumptions I have.
So here's the ...
1
vote
1
answer
52
views
What are the binary representations for the flags used in the Linux open() syscall?
I am learning NASM and currently unsure what values should be used for the flags argument for open() as shown in the man page. I'm mainly asking this for clarification so I don't mess something up, ...
-1
votes
0
answers
22
views
I got collect2: error: ld returned 1 exit status [duplicate]
I have this simple function that finds hypotenuse by given 2 sides in right triangle. I INCLUDED math.h.
#include <stdio.h>
#include <math.h>
double findHypotenuse(int a, int b)
{
...
-2
votes
0
answers
25
views
Terminal do vscode imprimindo % [closed]
meu vs imprime no terminal % após números
enter image description here
Pesquisei e não achei o motivo do terminal imprimir % depois de números, alguém ja enfrentou esse problema e sabe como resolver? ...
0
votes
0
answers
18
views
How do I fix the Java unsatisfied link error when using JNA in Apache MiNiFi running inside a podman container
I have an Apache NiFi dataflow that transports data between two directories on my system through POSIX message queues using two NiFi processors that I made. These processors use JNA to make the calls ...
-1
votes
0
answers
72
views
Can't use functions on baremetal Arduino? [closed]
I've been trying to work with an arduino UNO, programing the atmega328p using bare-metal C. I can do basic things such as reading and writing and all that, however I can't make a program that uses ...