|
Your function is returning by value, which your code is ignoring (discarding).
A Google search for "attribute nodiscard" provides the answer.
C++ attribute: nodiscard (since C++17) - cppreference.com[^]
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
I know that, but the description is not clear about the differences if any between the nodiscard for the struct vs for the function.
I'd rather be phishing!
|
|
|
|
|
Well,
That attribute is weakly defined in section 10.6.7 of the standard. You can go read it yourself. The behavior is intentionally vague using words like 'encouraged' and 'discouraged'. Regardless of whether it's applied to a function or class there is no difference defined.
In fact if you carefully read the document no behavior has been defined. The only section without 'encouraged' and 'discouraged' is section 1 where the attribute token "[[nodiscard]]" itself is defined.
In other words in C++17 the only guarantee is that your compiler understand the [[nodiscard]] attribute. No behavior is defined.
Best Wishes,
-David Delaune
|
|
|
|
|
There is no difference you are discarding something (you didn't save it) that was marked as non discard.
The whole idea should have been euthanized, it is what you get when you get a committee to talk about non existent problems.
There are half a dozen real problems but they waste time on that junk.
Here is the best template to fix [nodiscard]
template < typename T >
void ignore(T&&) {}
Try it on your code
ignore(f1());
Now don't make me do it .... if I want to discard something I will
In vino veritas
modified 5-Apr-19 9:40am.
|
|
|
|
|
LOL
I think someone got tired of programmers who do not follow the good practice of checking returned values and decided to provide a standard way to warn them. The problem with that is those same programmers also tend to ignore warnings.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
John R. Shaw wrote: ... same programmers also tend to ignore warnings.
But, but, if it compiles, I'd then not need to worry about the warnings, right?!
|
|
|
|
|
Hope can post this question on this forum.
I was under believe that triplet means three in format:
CPU-company-OS
So why is config.guess adding -gnu as fourth value?
I do not see any tangible benefits in reporting "gnu".
$ sudo bash config.guess
x86_64-pc-linux-gnu
Cheers
|
|
|
|
|
to a certain extent its the GNU foundation being picky. the systtem is "linux-gnu" i.e. a linux kernel with GNU infrastructure tools. AFAIK there's no other tools running on a linux system, but that doesn't mean there couldn't be.
why are you using sudo in this situation? it shouldn't be neccessary
|
|
|
|
|
Using sudo because it works.
Now I may have to modify the code to look for "linux-gnu", See no issues doing that.
|
|
|
|
|
Vaclav_ wrote: Using sudo because it works.
If it only works with sudo then you've seriously borked your system. If commands work without sudo, then please stop doing that ... eventually you're going to do something like
$ cd /bin
do some more things, time passes, you forget where you are ...
$ sudo rm * ##whoops ... there goes everything in /bin .. time to recover from backups or re-install, more likely
Don't tell me it will never happen to you ... it just hasn't happened to you yet. Something like that has happened to almost everyone that has had root privileges on unix or unix-line system system. That's partially why login as root is generally discouraged. But if you insist on prefixing almost everything with sudo, you might as well just enable root login on your system and go from there.
|
|
|
|
|
|
so that would be armXX-unknown-linux-uClibc, then? Interestingly FreeBSD (i386, 9.1 - old, i know) reports i586-unknown-freebsd9.1. No mention of the the c-library involved.
|
|
|
|
|
Well,
Rather than speculate about what it could be let's just take a direct look at the latest source code;
gcc/config.guess at master · gcc-mirror/gcc · GitHub
case "$UNAME_SYSTEM" in Linux|GNU|GNU/*)
# If the system lacks a compiler, then just pick glibc.
# We could probably try harder.
LIBC=gnu
#if defined(__UCLIBC__)
LIBC=uclibc
#elif defined(__dietlibc__)
LIBC=dietlibc
#else
LIBC=gnu
#endif
EOF
eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`"
# If ldd exists, use it to detect musl libc.
if command -v ldd >/dev/null && \
ldd --version 2>&1 | grep -q ^musl
then
LIBC=musl
fi
;;
esac
So looks like the possible values are:
Best Wishes,
-David Delaune
|
|
|
|
|
It is actually even more convoluted.
If I want to cross-compile - in Eclipse IDE I add "prefix "arm-linux-gnueabi- which translates to "arm-linux-gnueabi-gcc"
That is the actual name of executable cross compiler, not a meaningless triplet.
However , config.guess on Raspberry Pi (armv7l) is "armv7l-unknown-linux-gnueabihf".
That implies that the last member is not just some political peeve.
All this makes the package I am working on useless ( straight from the box) since it does not use the latest version of config.guess in the first place and has "configure" script with no code provisions to analyze the overgrown triplet.
|
|
|
|
|
Yeah,
Vaclav_ wrote: If I want to cross-compile - in Eclipse IDE I add "prefix "arm-linux-gnueabi- which translates to "arm-linux-gnueabi-gcc"
Reviewing the config.guess source I can see that it will append libc characteristics.
Vaclav_ wrote: All this makes the package I am working on useless ( straight from the box) since it does not use the latest version of config.guess in the first place and has "configure" script with no code provisions to analyze the overgrown triplet. Look, as you probably already know I am primarily a Microsoft technology guy. I left the Linux world over 15 years ago so I am extremely rusty on modern Linux. But I am currently using Linux again on a daily basis and cross-compiling my project so that it will run in Windows, Linux and hopefully any other embedded environments.
Maybe you should try my technique for cross compiling... I just build a quick chroot environment and custom-build the toolchain for whatever platform I am targeting. That's the way I've always cross compiled... but maybe I am using outdated techniques.
Best Wishes,
-David Delaune
[EDIT]
If you are feeling lazy I found an automated script on GitHub that should get you a working build environment for targeting the Raspberry Pi.
Creates a chroot environment for creating custom Raspbian images and cross-compiling programs for the Raspberry Pi.
|
|
|
|
|
If your coming thru a makefile you can pick the compiler OS inside the makefile I always do it because
I need to swing between RM and DEL and the directory slash in the makefile
You can change the compiler binary in that conditional as well.
ifeq ($(OS), Windows_NT)
#WINDOWS USE THESE DEFINITIONS
RM = -del /q /f
SLASH = \\
else
#LINUX USE THESE DEFINITIONS
RM = -rm -f
SLASH = /
endif
So ......
ifeq ($(OS), Windows_NT)
#WINDOWS USE THESE DEFINITIONS
RM = -del /q /f
SLASH = \\
CC = arm-none-eabi-
else
#LINUX USE THESE DEFINITIONS
RM = -rm -f
SLASH = /
CC = arm-linux-gnueabi-
endif
In vino veritas
modified 1-Apr-19 8:25am.
|
|
|
|
|
In object-oriented programming, why is combination better than inheritance in code reuse, for example, given the coordinates of two points to calculate the distance between two points, should the Distance class be inherited from the Point class or an object of the Point class as a data member of the Distance class?
|
|
|
|
|
The question comes down to is distance fundemental to point or is it a function executed and that is up to how you intend to use it.
The general rule is function over inheritance and it's clearly covered by wikipedia
Composition over inheritance - Wikipedia[^]
If point has shapes that derive from it and distance is the closest point between the two shapes then we can provide a clear implementation of how it must work.
The only way to reconcile the closest point between two complex shapes will be to run each geometry (line,arc,spline etc) of each shape against the other shape or scanline the two shapes in a minimal box that includes both shapes. Either of those two processes will require these functions
1.) reset or seek so a geometry index will be the next out (seek_geometry(i))
2.) retrieve the next geometry from the shape (read_geometry(i))
3.) check if this geometry was last, if not back to 2 we go (check_geometry_end).
Essentially the geometry callback function(s) will be inherited from point but the distance will be another object because it will take two objects and run the process. Distance can then evolve to take a list of objects or different sorts of objects.
It is easy to see in that situation distance is not really a function of a shape it is a function between two shapes. However it could also be between a shape and something else such as a bounding box or grid or something yet to be thought of. So from a flexibility and reuse point of view you code for functionality and make point and distance two different objects.
In the simplest example it would make little difference but the functionality coding would make it easier to extend, reuse and more flexible. Ultimately you are more likely to reuse the more flexible code.
In vino veritas
modified 31-Mar-19 12:21pm.
|
|
|
|
|
元昊 潘 wrote: ...should the Distance class be inherited from the Point class or an object of the Point class as a data member of the Distance class? Is a vs. Has a
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming:
1.write a method that accepts an array of integers as its parameter and returns the largest value.
2.given the <u>enum</u> below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting".
3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21};
-write a for loop that will find the lowest mark
-write a while loop that will find the lowest marks
-write a do....while loop that will find the highest marks
the programming language to be used is c
|
|
|
|
|
Please explain exactly what help you are asking for. But do not expect someone to do your work for you. If you do not understand the assignment then you should discuss it with your teacher.
|
|
|
|
|
|
|
Member 14203327 wrote: Please help me... What do you have so far? Around these parts, posted code usually results in critiqued code.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
this is the code that i had but when i run it, it gives me a 0(zero) as the answer
#include<stdio.h>
//program for finding the lowest value in an array using a for loop
int main (){
int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ;
for (marks[a]<marks[b];b++;){
lowest = marks[a];
a++;
}
printf("the lowest number in the array is %d", lowest );
return 0;
}
|
|
|
|