Vlad
Anonymous
How to globally declare variable in C
Alex
use extern
Anonymous
Thank you
Anonymous
What is the use of static
Alex
local variable, common variable for all function calls
Vlad
If not then static means visible for this .c file only
Anonymous
Okay
Anonymous
Extern is only way to globally initialize a variable
Alex
extern is not about initializing, its about declaration
Anonymous
Okay
V01D
Who wrote a music visualizer before and can help me out?
J
what kind of visualizer, what kind of help do you need?
Nils
Kind of
Nils
To declare a variable that was declared in another linked file already
Nils
So you can access that variable
Nils
Yeah
Vlad
In .c file
Nils
In another object file
Vlad
redefenition will fail on linking stage
Alex
file3.c = #include file2.h
Nils
file3.c = #include "file2.h"
Nils
No need to redeclare then
V01D
what kind of visualizer, what kind of help do you need?
An audio visualzer, meaning I give it a wav file and visualize it while playing it in real time.
I need help with the whole calculating the FFT part. More specifically, I cannot understand how to calculate the FFT from a .wav file. I need the FFT so that I can calculate the max magnitude for one audio sample. Then I will plot the image and repeat
Vlad
Redefenition in .C file will fail on linking stage. What didncha understand? :P
Vlad
In .c file it's definition
Vlad
And declaration is .h file
Nils
Just not redclare in file3.c
Vlad
Vlad
You define it once in your globals.c and all it a day.
Vlad
No
Nils
No just leave that line away
Nils
No, leave away "int smth;" from file3.c
Vlad
it's like that:
file1.h:
extern int global;
file1.c:
int global;
J
Vlad
And other files have nothing
Vlad
They include file1.h and use global variable
Nils
V01D
V01D
I have read so many different pieces of code, and until now I couldn't wrap my head around them. Seems to be this whole fft audio wave math thing I don't get..
Vlad
V01D
It's been 5 days with no progress
V01D
I quit for now, lol.
I just don't get it, and that is like the only thing I don't get... oh well
V01D
Wait what am I saying. Imma continue
MᏫᎻᎯᎷᎷᎬᎠ
what is the difference between usual threads, async functions and coroutines
数学の恋人
what is the difference between usual threads, async functions and coroutines
I'll try to say in simple words,
Threads - multiple jobs running parallel, multiple threads
Coroutines - multiple jobs, but running sequentially, one by one (one is executed at a time)
async - similar to coroutine, waits for one job to finish then programmer decide what to do next, do another job, contine same job, etc.
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
I mean by "controlled by the programmer" is
you won't be able to call
resume()
stop() / suspend()
olli
what is the difference between usual threads, async functions and coroutines
async
return before they complete.
e.g. you can have a function CopyFileAsync(From, To)
CopyFileAsync(From, To);
// call to the function returns but the copy might
// not be completed
thread
generelly independent execution of instructions
coroutines
only syntactical sugar, let's you write asynchronous code as if it were synchronous
co_await CopyFileAsync(From, To);
// Copied completed, but in the meantime, some
// other function was able to advance
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
and how Async can provide such thing if it doesn't use threads in its internal implementation
Anonymous
Anonymous
MᏫᎻᎯᎷᎷᎬᎠ
Anonymous
Basically it runs on a detached thread
Anonymous
Just watch some talks by Gor Nishanov in CppCon
Anonymous
It's the person that drives coroutines into C++ standard
Anonymous
MᏫᎻᎯᎷᎷᎬᎠ
Anonymous
I think you need to read something about Concurrency...
MᏫᎻᎯᎷᎷᎬᎠ
I know detach()
Anonymous
There's a book called C++ Concurrency in Action
MᏫᎻᎯᎷᎷᎬᎠ
lol
But what I was talking about
threads use more system resources
Anonymous
So?
Anonymous
Do you know what a thread pool is?
MᏫᎻᎯᎷᎷᎬᎠ
Yes??
olli
and how Async can provide such thing if it doesn't use threads in its internal implementation
let's assume you have a server, you listen for multiple connections to come in and for perf reasons you want to execute them concurrently. Most operating systems offer you a function to register that socket to an internal data structure, whenever one of those sockets is ready you get a "notification" which socket it is and you can resume handling the connection.
One abstraction level higher the connections seem to be asynchronous, potentially executing out of order.
MᏫᎻᎯᎷᎷᎬᎠ
what does thread pool has to do with this?
MᏫᎻᎯᎷᎷᎬᎠ
this is from Rust asynchronounce book
after all, threads were designed to do just this: run multiple different tasks at once. However, they also come with some limitations. There's a lot of overhead involved in the process of switching between different threads and sharing data between threads. Even a thread which just sits and does nothing uses up valuable system resources. These are the costs that asynchronous code is designed to eliminate. We can rewrite the function above using Rust's async/.await notation, which will allow us to run multiple tasks at once without creating multiple threads:
olli
e.g. you write readFromNetwork(socket);, you queues this request and either a provided callback or flag indicates your request has finished.
olli
no instead of passing callbacks you can use futures and chain them or use the syntactic sugar to just use await
olli
another neat use case for coroutines was to change threads, imagine you're writing a GUI application. Most frameworks use one main/render thread and all changes to UI should be made through that thread.
What people are doing is something like this
void RunOnUiThread(Cb);
void UpdateUI() {
auto Result = DoSomeComputations();
RunOnUiThread([&](){
UpdateUiWithResult(Result);
});
}
What coroutines allow you to do
void UpdateUI() {
auto Result = DoSomeComputations();
co_await SwitchToUiThread();
UpdateUiWithResult(Result);
}
MᏫᎻᎯᎷᎷᎬᎠ