Anonymous
I really thought that everything is file and therefore stdin has to be a file
They are all treated as files. But not all files are the same. There are different drivers handling different types of them If you look at a text file on an ext4 file system and the same file on a btrfs file system, they will look the same to you. But the calls that the kernel makes will be to different drivers to retrieve the file contents. The system call will be the same but the calls further down will be different.
klimi
Anonymous
but in the end... EOF is indicated with read so...
Yes the read system call needs to know that a EOF was encountered. That is how the kernel can inform the caller that a EOF occured without setting errno. If you look at the read system call documentation, you will know that EOF is inferred only from the count and it should be set to 0. The kernel has to return this value to the C and C++ standard library. While reading a file, the kernel uses the file struct to determine the current position int he file and the position of the last byte in the file. If the current position is greater than the last byte, then the kernel knows EOF has occured and it can indicate this from the read system call. For a terminal, the kernel cant know so. It relies on the driver to pass this information to it. The tty driver handles the CTRL+<> key combination and sends this info to the kernel. The kernel returns this as a part of the read system call.
The C/C++ standard library then use this return value to let the calling C and C++ code that EOF occured which can be tested in our code using cin.eof() etc.
klimi
Oh, i see you were talking about the kernel from the beginning, i was just talking about the ABI
klimi
i see :D
Sylvester Lim
Hey all, i would really appreciate if someone could show me the solution to this :
System shuffle and randomly assigned numbers 1-10 to the cards
My teacher said arrays cannot be used , as she havent taught us, this is intro to programming class.
i used this code:
int num1 = rand()%4+1;
cout <<num1;
int num2 = rand()%4+1;
cout <<num2;
(and so on until num10 because i wan 1-10)
the numbers seomtimes repeat
Pavel
Sylvester Lim
I tried the code , but some numbers are repeated
Sylvester Lim
Eg: 1234567888
Sylvester Lim
Yes sure i cannot use them as i havent been taught to use arrays
1. Player one and two enter their name
2. System shuffle and randomly assigned numbers 1-10 to the cards
3. Player one pick a card
4. System shuffle remaining cards and randomly assigned numbers 1-9 to the cards
5. Player two pick a card
I have to make a game for this
Pavel
Pavel
Or maybe you've been taught bit operations
Sylvester Lim
Nope, haven't learn functions. She taught us the basic stuff and some of the harder ones are like switch statement , while loop , if else , do while loop and for loop
Sylvester Lim
May I know what is bit operations ? Isit like && || and all? If so yes , taught
Sylvester Lim
Only learn &&(And) ||(or) ! (Opposite of expression) .
Nothing about bitwise and(&) ..etc
Not too sure if there are the same things
Sylvester Lim
I learnt the && || mainly got use in conditional statements .
Eg: while (x=5 && x=6)...
Pavel
Pavel
Sylvester Lim
Is the dumb way using loops (maybe while loop)?
If the number generated is same as previously generated number , then loop until u get a different number?
Sylvester Lim
Sylvester Lim
Bool returns 0 or 1 from what I know
Sylvester Lim
True / false
Sylvester Lim
Anonymous
Fenimoure
How do I stop this code from modifying list1?
void twoDirList::splice_in(biNode *list1front, biNode *list2front, int index) {
for (int i = 0; i < index; ++i) {
list1front = list1front->next;
}
list2front->prev = list1front;
while (list2front->next) list2front = list2front->next;
list2front->next = list1front->next;
list1front->next->prev = list2front;
while (list2front->prev != list1front) list2front = list2front->prev;
list1front->next = list2front;
}
Output:
list: 0 0 0 5 5 8 9 13 16 17
list1: 0 8 17 9 5 13 0 16 0 5
list spliced: 0 0 0 5 5 0 8 17 9 5 13 0 16 0 5 8 9 13 16 17
list1: 0 8 17 9 5 13 0 16 0 5 8 9 13 16 17
Anonymous
Fenimoure
you dont know what is this
I know. okay, I've asked. The second list has to be destroyed after using this function. Though, I can not use new and delete functions
Anonymous
Fenimoure
Anonymous
● Igor
i'm checking if here front and back aren't null pointers before calling delete:
class queue
{
queue_node *front = nullptr;
queue_node *back = nullptr;
public:
~queue()
{
if (front != nullptr)
delete front;
if (back != nullptr)
delete back;
}
};
● Igor
but i still get:
free(): double free detected in tcache 2
Ammar
but i still get:
free(): double free detected in tcache 2
The problem is not in the code you sent. That queue class is perfectly fine if it is used properly. That being said, the deleted pointer must be from a valid new.
The problem must be somewhere else in your code, not that code. You should post it.
Leovan
Someone can explain me on examples, please:
why I should use unnamed namespace in .cpp file for local const and local functions, how they can conflict with header's const with the same names (if i use in header same named const and include it, isn't a compilation error?).
I can't find adequate example.
Leovan
I have some constants in my .cpp file:
constexpr float delta = 0.01f;
why I should put them in unnamed namespace?
namespace
{
constexpr float delta = 0.01f;
}
Ahmed
Sup cool 😎 programmers.
Can I ask about something in my assignment, there are 2 weeks till the deadline comes
Ahmed
Is it ok in the rules?
Leovan
don't understand how they can conflict? anyway if i include header with same named constant i will receive compilation error
Leovan
Ahmed
Okay! It's a general question. I need to make a full atm C++ program with specific details that I won't bother you all with. To be specific, I need to make it by means of classes and member functions.
How can I check everypart in my member functions without the need to write the full program
Ahmed
I know how can I debug a full program, but I have never done that to functions and objects inside the code alone
Ahmed
Also if i have an array of objects inside a class how can I return to the value of a specific variable inside the array of objects without the need of dynamic memory allocation
Ahmed
Okay ty, what about my last question
Ahmed
Any suggestions on the best source to have a brief look at linked lists?
Ahmed
nvm bro ty anyways
QuarticCat🔮
Is there any thin SIMD wrapper library that simply wraps the compiler's vector extension types and provides overloaded intrinsics over them?
QuarticCat🔮
For example, when I declare a i32x8 variable and call set1 on it, I no longer need the _mm256_ prefix and the _epi32 suffix since they are implied by the type. With such a library I still hold full control of intrinsics but write less and clearer code.
QuarticCat🔮
If there is no such library I will write one, it seems easy.
Anonymous
QuarticCat🔮
Thank you! I'll have a look
Anthony
Hi
Pavel
Hey guys . Can i insert plus in variable ?
Pavel
Like:
Char A;
Int b, c;
Cin >> b;
Cin >> A;
Cin >>c;
Switch (A)
Case "+" :
Cout << "b + c";
Case "-";
Cout << "b - c";
神 ꜰʟᴀꜰꜰʏ
ofc
Ольга
Good day. I can't understand, so I hope for help, how can this
scanf("%[ ^\n] s", (ptr+i) - >name);
be corrected so that not one word but sentences with spaces are written down? Thanks in advance for the reply
Ольга
\Device\NUL
\Device\NUL
conko
conko
And note that your case should be `char`s, not string literals
Abhu
How you gonna use +,- case without specifying them or input them
Peace
anyone knows a good but free mindmap software for windows ?
Faramarz
Hello
I have a text file and I need to read the different information of this file under several functions, but when I start reading the file in a new function, fscanf does not read the information from the continuation and starts reading them from the first line. Can you help me to fix it?
conko
conko
You may need to refactor those functions to accept a FILE* parameter in order to share the same file stream
Ольга
Whats wrong
At compilation this field is simply passed. Works with a slightly different option but then only one word remembers that is that to the space
\Device\NUL
● Igor
when i create an array with a size that is unknown at compile time, is that going to be stored on the heap?
for example:
int n;
cin >> n;
int arr[n];
\Device\NUL
\Device\NUL
Also, ISO C++ doesn't support Variable length array
conko
and how the program manage to alloc space in the stack at runtime?
> As to how the compiler usually implements VLAs, it's the same as alloca() (except that it has to keep the size around for sizeof ) - the compiler saves the original stack pointer, then adjusts it down by however many bytes it calculates that it needs. The downside is function entry and exit is a bit more complicated as the compiler needs to store where to reset the stack pointer to rather than just adjusting by fixed constants.
conko
this is what I found on stack overflow, I copied the answer, having failed to send a link. Hope that'll help