Hema Hariharan
i = 10 ++i i = 11 ++i i = 12 i+i = 12+12 = 24
Accrding this we need to get 9 But i am getting 10
Eugene
That what i said
this is an invalid record. compiler dependent. Better such ambiguous records.
klimi
#include <stdio.h> int main() { int i=1,j; j= ++i + ++i + ++i; printf("\n%d",j); return 0; }
so we it is like ( (++i) + (++i)) + (++i) (or the other way around not sure, doesn't change the result (3+3) + 4 = 10
Deepak Chaurasia
Tell me where i am wrong 😅
klimi
i just hope i am not arguing with UB... :D but i feel like it should be ok
Hema Hariharan
Okay then...
#include <stdio.h> int main() { int i=1,j; j= ++i + ++i + ++i + ++i; printf("\n%d",j); return 0; }
Hema Hariharan
what abt this
klimi
kilmi acc to u we need to get 21 but op is 15
(((++i) + (++i)) + (++i)) + (++i) ((3+3) +4) +5 = 15
Dm
i = 10 ++i i = 11 ++i i = 12 i+i = 12+12 = 24
wow, I found the way how to get 23 :) just use clang or unusual compiler (zig cc, icx, TCC), not gcc
klimi
that's what i was worried about UB...
klimi
okay, i'll look into it
Dm
but in general it's not ++i + i++ that's why it looks little bit more legal
klimi
oh guess i dont have to worry about that ╰─ clang test.c test.c:5:8: warning: multiple unsequenced modifications to 'i' [-Wunsequenced] j= ++i + ++i + ++i + ++i; ^ ~~ clang even warns about it
klimi
with -Wall even gcc warns about it... i guess i should have enabled warnings from the beginning
Hema Hariharan
(((++i) + (++i)) + (++i)) + (++i) ((3+3) +4) +5 = 15
Ufff Y these people are assigning a tricky ques Anyway thank you so much @K11M1 🤝
Hema Hariharan
This is Undefined Behavior as well
Sorry i thought just a few lines
klimi
what i written is how gcc interprets this, but the result is uncertain
klimi
undefined behaviour
Anonymous
Sorry i thought just a few lines
You can read about Undefined Behavior in the Resources section of this group. Here is the link : https://t.me/cpp20programming/204
klimi
depending on compiler you can get different answers... (in this case)
Anonymous
depending on compiler you can get different answers... (in this case)
That is implementation defined behavior. Undefined Behavior means that the standard or the compiler offer no guarantees and anything can happen.
Hema Hariharan
undefined behaviour
Oh my sec i thought admin was saying undefined behaviour like i did something wrong in this grp 😅
Anonymous
In this case it should be the same no? ( i don't know)
No. In this case even on the same compiler between different runs, the output can be different. It can cause your system to crash. When output varies from compiler to compiler and it is documented, and the standard allows such differences, then it is called Implementation Defined Behavior. There is another thing called Unspecified Behavior. I have tried to explain all 3 of them here: https://t.me/cpp20programming/204
Nada
hello friends, I'm working on my first simple project and I face a lot of problems so if someone can help me, please I need help. thanks in advance
Nada
sorry
● Igor
Is it a bad idea to #include a .c file to avoid having to reference it on compilation time?
Thadeu
Is it a bad idea to #include a .c file to avoid having to reference it on compilation time?
I usually link to an external lib only when needed. To reuse my own code I write the library under the header, using an ifdef and ifndef. The functions being static so compiler has some hints. Look for https://en.m.wikipedia.org/wiki/Header-only
Anonymous
How to add an existing cpp file to a project in clion? without adding executables to cmake
Pavel
How to add an existing cpp file to a project in clion? without adding executables to cmake
If you use CMake you can add it to CMake (add to your executable sources list in one way or another) and reload CMake file in clion. Note that you can add multiple files to one executable in CMake and there are also options to add all files from a folder (glob).
神 ꜰʟᴀꜰꜰʏ
hello guys, i need help print words that begin and end with the same letter. words are separated by a space
klimi
hello guys, i need help print words that begin and end with the same letter. words are separated by a space
and like... in what part you need help? you don't know how to print the letter? how to access array?
Melpher
Hello?I want to ask how to convert between "const std::string" class and "std::string" class? However, what I found on the Internet are the conversions between const char* and string. . . ,thanks!😳
Melpher
now I know how to convert const string to string:
Melpher
but how to convert string to const string?
Ighor
but how to convert string to const string?
are you wish to edit the original const std::string ?
Melpher
yes
Melpher
Now I convert it to std::string and edit it and return it.and I find it no worth to return a const std::string.
Melpher
So my problem is solved ,thanks!
Billionaire
Hello, I want to print a pattern using C:
Billionaire
555555555 544444445 543333345 543222345 543212345 543222345 543333345 544444445 555555555
Chat Boss
योडा sent a code, it has been re-uploaded as a file
Anonymous
If you use CMake you can add it to CMake (add to your executable sources list in one way or another) and reload CMake file in clion. Note that you can add multiple files to one executable in CMake and there are also options to add all files from a folder (glob).
<quote>there are also options to add all files from a folder (glob).</qoute> This is a must be avoided feature in cmake. This screws up build rules and will bite you in the future if you later decide to replace globbing with a list of files instead.
● Igor
Hello, I want to print a pattern using C:
it seems to be the greatest distance to the center... basically compute the distance for the horizontal middle and for the vertical middle and print who is greater
Chat Boss
Suraj Kumar sent a code, it has been re-uploaded as a file
Pavel
<quote>there are also options to add all files from a folder (glob).</qoute> This is a must be avoided feature in cmake. This screws up build rules and will bite you in the future if you later decide to replace globbing with a list of files instead.
Adding files manually to cmakelists every time is super annoying, I have read that it's suggested to avoid it, but I don't see how it can break anything and what are alternatives that don't require doing things manually. I can't imagine going back to listing every single file (a lot of my cpp/h files also generated with script that called from CMake)
神 ꜰʟᴀꜰꜰʏ
what do you mean? Is it like polindrom words?
not necessarily a palindrome, it can be for example "helloh hi world" and i need print "helloh"
Anonymous
Adding files manually to cmakelists every time is super annoying, I have read that it's suggested to avoid it, but I don't see how it can break anything and what are alternatives that don't require doing things manually. I can't imagine going back to listing every single file (a lot of my cpp/h files also generated with script that called from CMake)
It is bad for many reasons. If you are working in a group and your cmakelists.txt file uses globbing. Suppose you add a new file A.cpp and commit it. Suppose some other developer who has built his project recently, does a pull - since his CMakeLists.txt file has not changed, the build system will conclude that nothing needs to be built again. And the build would fail. This can be corrected by using CONFIGURE_DEPENDS. But this brings with it its own set of issues. Now incremental builds are slowed down. For the ninja generator, which is considered to be the fastest build system in existence on *nix systems, CONFIGURE_DEPENDS brings down performance so much. This is because everytime you kick off a build a check is performed to see if any new file has been added to the filesystem. This is a very slow process and decreases the value of TDD for incremental builds that pisses off people who work on a source system that has more than a MLOC. And btw CONFUGURE_DEPENDS is not guaranteed to work with every generator. Another solution that is considered for such issues is to check constantly for changes on the filesystem using things like inotify and stuff. But this is so fragile that even a small change in things like cgroups limits can cause his monitoring to break which in turn would break your build and tracking suck things would be a big pain in the a**. And even if you have a lot of generated source files, assuming they are all generated by the same process, you can always use a custom target and then create an implicit dependency to your final Target. The generator would be triggered through a custom command. This would totally negate the requirement for globbing given all the disadvantages above.
Pavel
It is bad for many reasons. If you are working in a group and your cmakelists.txt file uses globbing. Suppose you add a new file A.cpp and commit it. Suppose some other developer who has built his project recently, does a pull - since his CMakeLists.txt file has not changed, the build system will conclude that nothing needs to be built again. And the build would fail. This can be corrected by using CONFIGURE_DEPENDS. But this brings with it its own set of issues. Now incremental builds are slowed down. For the ninja generator, which is considered to be the fastest build system in existence on *nix systems, CONFIGURE_DEPENDS brings down performance so much. This is because everytime you kick off a build a check is performed to see if any new file has been added to the filesystem. This is a very slow process and decreases the value of TDD for incremental builds that pisses off people who work on a source system that has more than a MLOC. And btw CONFUGURE_DEPENDS is not guaranteed to work with every generator. Another solution that is considered for such issues is to check constantly for changes on the filesystem using things like inotify and stuff. But this is so fragile that even a small change in things like cgroups limits can cause his monitoring to break which in turn would break your build and tracking suck things would be a big pain in the a**. And even if you have a lot of generated source files, assuming they are all generated by the same process, you can always use a custom target and then create an implicit dependency to your final Target. The generator would be triggered through a custom command. This would totally negate the requirement for globbing given all the disadvantages above.
In the teams I worked with you always call cmake to update the project after you pull (usually from custom script that does other housekeeping as well). Cmake is pretty smart about updating the project, and fast. I've never actually seen any project where people would edit cmakelists manually unless they want to change build rules.
Pavel
When did I say that you have to edit CMakeLists text file?
How it's going to be changed if not edited
Anonymous
How it's going to be changed if not edited
When did I say that you have to change CMakeLists.txt file everytime you trigger a build?
Pavel
When did I say that you have to change CMakeLists.txt file everytime you trigger a build?
Not every time you trigger a build, at all, when you add/delete/rename file for example, we don't do that
Anonymous
Not every time you trigger a build, at all, when you add/delete/rename file for example, we don't do that
I am not sure if you understood what I was trying to say. Tell me which part is causing confusion so I can clarify
gp9
hello everyone
Pavel
I am not sure if you understood what I was trying to say. Tell me which part is causing confusion so I can clarify
You say that glob is bad because cmakelists won't be updated and it can cause build failure, I say that it's solvable by running cmake after you pull new changes
Anonymous
but when the UEFI finds the EFI partition, how do it know which file contains the bootloader?
Well it depends on the NVRAM configuration. Try the command efibootmgr on your Linux system. It will list things like BOOT0001, BOOT0002 and so on. Each of them will point to an .EFI file in the EFI partition. The UEFI system will choose the .efi file accordingly
Anonymous
You say that glob is bad because cmakelists won't be updated and it can cause build failure, I say that it's solvable by running cmake after you pull new changes
If you run cmake and then do a cmake --build, then you again do what I suggested. That is the equivalent of scanning the filesystem for changes. That is what I said is slow. On an incremental build system, you don't need to call cmake again and again. The configuration and generation step need not happen everytime.
Anonymous
but whats in the efi partitions that makes the UEFI choose
The .efi files are in the EFI partition.the UEFI NVRAM configuration tells UEFI Firmware code which efi file to boot from.