Hussein
Problem is people use what they know. After education students will famous with C, so much probably will use in work and software what they will develop will suffer from C problems
this is not always the case C has advantages that C++ doesn’t have, even assembly has advantages that C doesn’t have (if you program on AVL architecture you will know what I mean) also with advanced projects you are more likely to use kernel libraries and your code will look like C anyway in terms of memory safety, because using a general purpose library doesn’t always work the best. also outside of the userspace, C is dominant in the kernel space or even on bare metal
Hussein
I don't think someone will allow junior devs to write something in the language they want (can be, but unlikely), the problem is mostly when people write C++ code as if it's C. So you there's a need to unlearn some C stuff later if going to C++. However today one can go to Rust from C instead.
the transition from C to Rust is really painful, even worst than C to C++. Rust is a very alien language for C devs. the language has a billion keywords to remmeber and very complicated compared to C syntax or even C++.
Saro
I think that will not that much painful.
Aquatica
What about transition from C to Go?
How are they even related
Hussein
How are they even related
both made by the same person and both follow the same paradigm
Hussein
both made by the same person and both follow the same paradigm
maybe not using pointers is bit annoying but it is a LOT easier than Rust or C++
Daulet
maybe not using pointers is bit annoying but it is a LOT easier than Rust or C++
after adding generics complexity grown, but not so much
Hussein
What about transition from C to Go?
it is MUCH easier, maybe a little bit annoying because you are using a garbage collector instead of doing things manually, and few other stuffs but you can get used to them anyway. In general it is almost the closest modren language to C (after lisp maybe).
frei
hello, I want to use vs code for c, I installed mingw-64, I wanted to run a code, but it gave an error, how can I fix this error? c: The term 'c' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelli ng of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + c exe.c +~ : ObjectNotFound: (c:String) [], CommandNotFoundException + CategoryInfo + FullyQualifiedErrorId : CommandNotFoundException
frei
gcc exe.c
Thanks ☺️
pavel
Main problems to move from C to Rust is mutability. Rust is friendly when variables most constant. But if you need an arrays of mutable variables you will have much pain to handle it
Marlo
Guys any website that i can have any exercises to learn coding? I'm studying computer science and it's my first year. Anyone that can help me? Thank you!
Pablo
guys, I have typed nonsense things in the "prefix" area inside the pkg-config file of my project and yet it runs, why?
Pablo
I think my computer has acquired intelligence
Pablo
finally
Pablo
https://prnt.sc/y88RLaWAd4-O
Babasaheb
now i study the union type,i get confused with following program, why the ch is 1,not 255 ?
Babasaheb
#include <iostream> using namespace std; union Port{ bool bit[8]; unsigned char ch; } P0; int main() { P0.bit[0] = true; P0.bit[1] = true; P0.bit[2] = true; P0.bit[3] = true; P0.bit[4] = true; P0.bit[5] = true; P0.bit[6] = true; P0.bit[7] = true; cout << P0.bit[0] << P0.bit[1] << P0.bit[2] << P0.bit[3] << P0.bit[4] << P0.bit[5] << P0.bit[6] << P0.bit[7] << endl; //P0.ch = 0xff; cout << "---->" << int(P0.ch) << endl; return 0; }
Babasaheb
output: 11111111 ---->1 Press <RETURN> to close this window...
Babasaheb
according to the book ,the "bit[8]" array and "ch" are sharing the same memory
Ammar
according to the book ,the "bit[8]" array and "ch" are sharing the same memory
bool bit[8] is 8 bytes in size here. ch takes the same place with bit[0] in your code.
Babasaheb
ok, i know why,thanks
Ammar
unsigned char ch is 1 byte in size, while your bool bit[8] is 8 bytes in size. Part of bit takes the same place with ch. It's the first member of the array, so when you change bit[0], it's also applied to ch. Change to bit[1] to bit[7] won't affect ch.
Babasaheb
can i manipulate every bit of ch
Ammar
can i manipulate every bit of ch
Yes, you can do something like this: #include <iostream> using namespace std; union Port { struct { unsigned char bit0: 1; unsigned char bit1: 1; unsigned char bit2: 1; unsigned char bit3: 1; unsigned char bit4: 1; unsigned char bit5: 1; unsigned char bit6: 1; unsigned char bit7: 1; }; unsigned char ch; } P0; int main() { P0.bit0 = 1; P0.bit1 = 1; P0.bit2 = 1; P0.bit3 = 1; P0.bit4 = 1; P0.bit5 = 1; P0.bit6 = 1; P0.bit7 = 1; cout << int(P0.ch) << endl; return 0; }
Babasaheb
looks perfect,l love u,thanks
Ammar
JFYI. Though this would behave the way you expect it to (most implementations offer this behavior as an extension), usage like this is still classified as Undefined Behavior according to the standard.
Yes, thanks for the tip. I understand C++ explicitly prohibits type pun via a union, but GNU extension. This is however valid in C. It will be implementation-defined. from C11 spec (n1570), page 83: 95) If the member used to read the contents of a union object is not the same as the member last used to store a value in the object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the new type as described in 6.2.6 (a process sometimes called ‘‘type punning’’). This might be a trap representation.
Ammar
Your code was C++ :)
Yes, I am fully aware of that.
Anonymous
(as far as I know)
It is indeed compiler dependent.
Anonymous
(as far as I know)
An implementation may allocate any addressable storage unit large enough to hold a bitfield. If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit. If insufficient space remains, whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is implementation-defined. The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined.
Anonymous
can i manipulate every bit of ch
Why not bit manipulation
Shutz
👋hello guys
Shutz
Please I need a huge help right now
Babasaheb
Why not bit manipulation
i don't know what you say,maybe i haven't learned that😁
Anonymous
i don't know what you say,maybe i haven't learned that😁
I didn't read the rest but if you're treating the character as an eight bit array, and you want to "turn on" the nth bit from the right, you could do ch |= 1<<(n-1) For example, char ch = 0; ch |= 1<<3; ch will now be 00001000
Alireza
how knows about aspose word cpp
Shutz
Please guys how can I code a crypter
Anonymous
your code is simple and pretty, but i want a intuitive one to access data ,that's why i encapsule it ,thanks for your kind heart
You should use a std::bitset<8> then. That would be more apt for the operations that you intend to do instead of hacking away at a union which may result in behavior counter intuitive to what you seek to do.
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, how do I end a thread after a timeout? I have a Server that creates multiple threads in order to handle several users, and each user is given a thread. Now, if the user does not give an input after xx seconds, the thread must be shut down, the problems are: 1) I don't know how to count the passing of time in C; 2) Even if I knew, I'd need the shutdown to activate if and only if nothing has happened during the xx seconds, and therefore I would need, I think, some kind of signaling; 3) I saw some functions on stack overflow, the problem is that if I search them on the man, I get nothing, therefore I am afraid they might not be standard and, therefore, the professore might not accept the usage of such functions
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
do you have any suggestions?
urs
Hi guys I'm new to this group can anyone suggest how to learn C
urs
I just completed my 12th
Ludovic 'Archivist'
Hi guys I'm new to this group can anyone suggest how to learn C
Do you have previous knowledge of another programming language?
urs
Nope
urs
I have 0 knowledge about this
Ludovic 'Archivist'
I have 0 knowledge about this
The C Programming Language by Brian Kernighan and Dennis Ritchie is a good starting point, but is also insufficient. some domain specific book should be read afterwards with exercices or practical projects to work on
Ludovic 'Archivist'
I would also recommend that once you feel confident in your knowledge of C you learn another programming language that is wildly different from it, like Scheme, Elixir, Clojure...
urs
What's Brain Kernighan and dennis ritchie?
Ludovic 'Archivist'
These fellas
Ludovic 'Archivist'
urs
I'm learning from w3 schools is it sufficient??
Ludovic 'Archivist'
I recommend the book, but it is a thing that exists
urs
Yes please
Ludovic 'Archivist'
Yes please
Like really, the title is The C Programming Language and Brian Kernighan and Dennis Ritchie are the authors
Ludovic 'Archivist'
They didn't name it anything original
urs
Yeah thats fine 😊
Ludovic 'Archivist'
The most important thing to learn in programming is to learn to learn. Sadly I can't think of a catchy name to write a book about that.
klimi
?
As to my I don't think w3 is enough/good material if you use solely that
Hussein
What's Brain Kernighan and dennis ritchie?
the guys behind unix and the C programming language
pavel
?
Nope