Anonymous
But not found
Anonymous
I think you didn't understand my question
Anonymous
I did
Anonymous
Read the docs
Anonymous
Ok
Velan Chandrasekar
Prince Of Persia
How to scanf a register?
Prince Of Persia
Anonymous
I mean register keyword
Register suggests to use a register but doesn't force it. The compiler can refuse to use the register. A register int cannot be used with pointers though. So you can't address it in the standard way
Ammar
Simply because you can't take address of register.
register int a;
You can't use &a.
Ammar
If you specify it like this
register int a asm("eax");
Then a will always be eax, compiler is not allowed to assume the variable as another register nor memory anymore.
Suka
Ammar
ברני
Anonymous
Ilya
Not at all. While programming Linux kernel modules, you may want to trace your program in runtime (via eBPF, for example) some registers (especially which are used to pass the arguments to the functions).
Anonymous
Anonymous
Using the register keyword or not, will not alter the core of debugging in kernel development
Ilya
It is not debugging
Ilya
https://ebpf.io/
Anonymous
Ilya
C++ programmers cant program Linux modules
Ilya
Only C
Anonymous
You are not required to do this. Tracing a program is a different world compared to using the register keyword or not
Ilya
@Danya If not considering special cases, ok, I agree
Anonymous
Even if you need to trace a specific register, the register keyword is not related to the problem at hand
Ilya
Ok, dude. You just dont know what are you talking about
Anonymous
Ilya
Linux kernel modules are running in kernel space
Anonymous
Anonymous
sure, so?
how does this relate to my knowledge in other languages?
Ilya
I wasnt correct. C++ programmers can write these modules, but not in C++
Ilya
That was the idea
Anonymous
Ilya
@rellc There are no non-specific applications, you are right
Anonymous
it's not that you can't, it just will be much harder then it should be, and makes 0 sense to even try
Anonymous
It's technically possible to use C++ for a module. But it will be a nightmare and you will need to perfectly replicate the C ABI
Anonymous
Ilya
Of course, you can write your own C++ compiler for linux kernel, or you can try to use LLVM (how it is with Rust)
Ilya
but for what?
Mar!o
How is the register keyword use in not specific programming related to kernel development?
The register keyword is ignored by the most compilers.
The idea was that the variable is used very much (for example in a loop), so it should reside inside a register.
But the compilers know register allocation better, so most of them ignore it.
But if you declare a variable with the register keyword, you can no longer get an address to it because you cannot have an address to a register.
register int x;
int* y = &x; // won't work
Anonymous
Mar!o
Anonymous
but for what?
I don't know, you just said it's impossible as a fact. lol
Ilya
You are cling to words, guy
Janko Ⓥ
Anonymous
Anonymous
Though they have plans to rewrite in C++
Anonymous
Ilya
I think Janko told about g++
Anonymous
https://github.com/gcc-mirror/gcc/tree/master/gcc/cp
Ilya
Oh, really. I didn/t know about the fact
Anonymous
Anonymous
It's a daily mirror
Anonymous
The team behind GCC told officially that C++ is an admissible language as long as it is used in a sensible way. In the present though, C++ has not been used widely by those programmers
Anonymous
Outside libstdc++ you will hardly find C++
Janko Ⓥ
janko@laptop gcc $ find . -iname *.c | wc -l
63229
janko@laptop gcc $ find . -iname *.cpp | wc -l
245
Drat. Well, it's built as a C++ program by default since 2012 or so. It's nominally a C++ program.
Anonymous
Anonymous
Or a part of libstdc++
Janko Ⓥ
Irrelevant, I'd say? C++ features are used for the C compiler. Would you call Linux an assembly program since it contains a lot of assembly code? The same logic may apply here, C is auxiliary
Anonymous
Janko Ⓥ
Anonymous
If a C program has a minimal part in C++ it's not a C++ program
Anonymous
Janko Ⓥ
That's why I stressed nominally
Anonymous
Janko Ⓥ