- meta-question: How do I get each post to this list emailed to me? - 4 Updates
- How to deal with running out of stack space? - 2 Updates
- int (*call_vec[])(void) ? - 8 Updates
- Overload by return type - 7 Updates
- strcmp() ? ;-) - 1 Update
- Namespace scopes and function implementation confusion - 1 Update
- when would one use a structure with an omitted tag - 1 Update
- Overload by return type - 1 Update
rh kramer <rhkramer@gmail.com>: Jun 20 05:51AM -0700 Why does this group work different than other googlegroups to which I am subscribed, and can I change it? The other googlegroups to which I am subscribed send an email to me for each post to the list. When I first signed up to this group (a day or so ago), I thought it was completely dead as I saw no posts. I eventually found a place to choose a setting, and chose this: Email delivery preference: Send combined updates (25 messages per email) On the other lists to which I am subscribed, the choices include: Email delivery preference: Notify me for every new message (about 2 per day) I do not see that choice for comp.lang.c++. I'm guessing that I can't get an email for each post, or am I missing something? Is this because it is a (very) high traffic list? |
James Kuyper <jameskuyper@alumni.caltech.edu>: Jun 20 09:24AM -0400 On 6/20/19 8:51 AM, rh kramer wrote: > Why does this group work different than other googlegroups to which I am subscribed, and can I change it? > The other googlegroups to which I am subscribed send an email to me for each post to the list. Google groups also allows you to treat comp.lang.c++ as if it were a mailing list, but it's actually a usenet newsgroup. Google groups allows you to access usenet newsgroups as if they were Google groups, but they don't actually belong to Google. > Email delivery preference: > Notify me for every new message (about 2 per day) > I do not see that choice for comp.lang.c++. I've had "comp.lang.c++" marked as a favorite in google groups, but I never joined it before, but in response to your message, I just did so. When I go to "My groups", comp.lang.c++ shows a box containing the text "Don't send e-mail updates", which is my preferred setting. That box also has a down arrow on the right. When I click on the down arrow, four choices appear: Don't send email updates Send daily summaries Combined updates (25 messages per email) Every new message I've no idea why you're seeing a different list of options. > I'm guessing that I can't get an email for each post, or am I missing something? > Is this because it is a (very) high traffic list? No, this isn't a very high traffic newsgroup. |
rh kramer <rhkramer@gmail.com>: Jun 20 06:33AM -0700 On Thursday, June 20, 2019 at 9:24:39 AM UTC-4, James Kuyper wrote: > Send daily summaries > Combined updates (25 messages per email) > Every new message Thanks for looking -- I went back to that menu / text box to see if maybe I had to scroll down to see the "Every new message" choice, but, no, I don't -- for some reason I see only the first 3 choices. |
David Brown <david.brown@hesbynett.no>: Jun 20 03:48PM +0200 On 20/06/2019 14:51, rh kramer wrote: > I do not see that choice for comp.lang.c++. > I'm guessing that I can't get an email for each post, or am I missing something? > Is this because it is a (very) high traffic list? This is not a "google group". It is a Usenet group. Google has their own group system, which is completely separate, and they have an interface to Usenet. Their Usenet interface is poor for normal use (though it's handy for wide searches, or occasionally looking at a group). If you find the group interesting and want to read it regularly and contribute, then I recommend getting a proper Usetnet client (Thunderbird is popular and works on all systems, but there are many alternatives) and a Usenet server (news.eternal-september.org is a popular free choice). |
Tim Rentsch <tr.17687@z991.linuxsc.com>: Jun 20 06:28AM -0700 > bytes and uses 5 C++ function call frames. The full C++ stack in > the debugger is 1067 frames deep and uses up 1MB (the default stack > size in MSVC++). (<aside>A default of only 1MB for the stack is -- please excuse my emphatic comment -- inexcusable in this day and age, and was even 20 years ago.</aside>) > This example just shows that using such strong words like "never" > and "infinitely long" is not quite appropriate, one can get stack > overflow pretty easily. It's not a purely academic concern. Nice example. The conclusion is directly on point. I think there is another lesson here that is worth pointing out. The difficulty in this case is not recursion but using linear recursion rather than logarithmic recursion. It is fairly straightforward to write a recursive factorial algorithm that divides the range into two halves at each step, giving a stack depth that is logarithmic in N rather than linear in N. (Doing this also gives a significant performance improvement in cases where multiple-precision arithmetic is involved.) Recursion that is logarithmic in problem size should never present a problem with using too much stack space (not counting very severely constrained execution environments, which have their own special considerations). Recursion is a powerful tool, but like any tool it should not be used indiscriminately or naively. Which is basically the same as what you were saying. |
Tim Rentsch <tr.17687@z991.linuxsc.com>: Jun 20 06:43AM -0700 > effect, and concluded that it didn't. It seems to me that it is > an observable effect in the abstract machine which we are looking > for. I believe this conclusion is correct. Observable behavior is always about behavior specified in the abstract machine, not about what might occur in the actual machine. > Perhaps the one or two posters who read the C++ standard ten > times before breakfast could help us. My comment is based on a memory of an earlier reading in the C++ standard (and many earlier readings of the C standard). I haven't gone back (at least not yet) and double checked this; I'll try to post a followup if and when I do. |
G G <gdotone@gmail.com>: Jun 19 09:51PM -0700 i saw this on the internet could you please explain? int anArray[] = { 6, 7, 8, 9 } --- array initialized such that: anArray[0] = 6 anArray[1] = 7 anArray[2] = 8 anArray[3] = 9 int *ptr --- is a pointer to int int *(ptr[4]) ---- is an array of pointers to int ? int *ptr[4] ---- ? (same as above ?) int ( *ptr[]) (void) --- ouch? thanks. |
G G <gdotone@gmail.com>: Jun 19 10:32PM -0700 > int ( *ptr[]) (void) --- ouch? > thanks. i found the answer i do believe : from: https://stackoverflow.com/questions/252748/how-can-i-use-an-array-of-function-pointers int sum(int a, int b); int subtract(int a, int b); int mul(int a, int b); int div(int a, int b); int (*p[4]) (int x, int y); int main(void) { int result; int i, j, op; p[0] = sum; /* address of sum() */ p[1] = subtract; /* address of subtract() */ p[2] = mul; /* address of mul() */ p[3] = div; /* address of div() */ [...] To call one of those function pointers: result = (*p[op]) (i, j); // op being the index of one of the four functions new question : is there a better way to do this using objects? |
Paavo Helde <myfirstname@osa.pri.ee>: Jun 20 09:43AM +0300 On 20.06.2019 8:32, G G wrote: > To call one of those function pointers: > result = (*p[op]) (i, j); // op being the index of one of the four functions > new question : is there a better way to do this using objects? In C++ the above can be written e.g. as: #include <vector> #include <functional> using func_t = std::function<int(int, int)>; std::vector<func_t> p = { [](int x, int y) {return x + y; }, [](int x, int y) {return x - y; }, [](int x, int y) {return x * y; }, [](int x, int y) {return x / y; }, }; int main() { // ... } |
Bart <bc@freeuk.com>: Jun 20 11:22AM +0100 On 20/06/2019 05:51, G G wrote: > int *(ptr[4]) ---- is an array of pointers to int ? > int *ptr[4] ---- ? (same as above ?) > int ( *ptr[]) (void) --- ouch? 'Ouch' as in 'what the hell does this mean', or 'what do you use it for'? If the former, then you might try: https://cdecl.org, which turns such declarations into English, or vice versa. However - 'ptr' appears to mean something special there, and generates a syntax error. So try a different name, like 'p'. |
David Brown <david.brown@hesbynett.no>: Jun 20 02:16PM +0200 On 20/06/2019 12:22, Bart wrote: >> anArray[2] = 8 >> anArray[3] = 9 >> int *ptr --- is a pointer to int It is common in C++, but by no means universal, to write this as int* ptr; This reads as "ptr is a pointer-to-int". In C, it is common but far from universal to write: int *ptr; Reading as "*ptr is an int". C++ emphasises the type, C emphasises the use of the identifier. >> int *(ptr[4]) ---- is an array of pointers to int ? >> int *ptr[4] ---- ? (same as above ?) If you write this as: int* ptr[4]; it becomes clearer. >> int ( *ptr[]) (void) --- ouch? C declarations are based on their usage. So this means that "ptr[100]" would be a pointer to a function that takes no parameters (void), and returns int. So "ptr" is an array of such pointer functions. You can't have "int ( *ptr[]) (void);" on its own, just as you can't define "int x[];" on its own, as the compiler doesn't know the number of elements. You have to have a size for the array, or an "extern". > declarations into English, or vice versa. > However - 'ptr' appears to mean something special there, and generates a > syntax error. So try a different name, like 'p'. Just to be clear - this is an artefact of the cdecl.org website. "ptr" has no special meaning in C or C++. If you find cdecl.org a useful tool, great. Personally, I much prefer to use typedefs to make complex types clearer. Obviously you can only do that when you write code - when reading other people's code, you have to understand what /they/ write. So if this array was for a collection of prime number generator functions, I'd use: typedef int (*FPrimeGenerator)(void); extern FPrimeGenerator generatorFunctions[]; |
James Kuyper <jameskuyper@alumni.caltech.edu>: Jun 20 08:33AM -0400 On 6/20/19 12:51 AM, G G wrote: > anArray[3] = 9 > int *ptr --- is a pointer to int > int *(ptr[4]) ---- is an array of pointers to int ? Keep in mind the basic principle of C declaration: declaration syntax mirrors the corresponding expression syntax. That declaration says that *(ptr[i]) is a valid expression for any value of i greater than 0 and less than 4, and that the type of that expression is "int". In the expression *(ptr[i]), the parentheses are unnecessary - it has exactly the same meaning as *ptr[i]. The same is true of the corresponding declaration. Such unnecessary parentheses are permitted in declarations, but should be avoided, because they can be confusing, as you have seen. > int *ptr[4] ---- ? (same as above ?) > int ( *ptr[]) (void) --- ouch? This is one of ways that the basic principle breaks down. (void) is a parenthesized argument list for a function, with "void" indicating that the function takes no arguments. The empty square brackets indicate that an array is being declared, with the length of the array being determined by the number of initializers provided for that array. You don't provide the entire declaration, but for the sake of argument let's pretend that four initializers are provided. Then this declaration says that the expression (*ptr[i])() is a valid expression for 0<=i && i<4, and that the type of that expression is "int". Therefore, ptr is an array, ptr[i] is an element of that array, *ptr[i] is a function, *ptr[i]() calls that function, and has the type int. Therefore, ptr is an array of pointers to functions that take no argument and return an int. |
G G <gdotone@gmail.com>: Jun 20 06:35AM -0700 On Thursday, June 20, 2019 at 8:33:18 AM UTC-4, James Kuyper wrote: |
G G <gdotone@gmail.com>: Jun 20 06:42AM -0700 > > array, *ptr[i] is a function, *ptr[i]() calls that function, and has the > > type int. Therefore, ptr is an array of pointers to functions that take > > no argument and return an int. thanks i don't think i'm asking this right but, here we go in OOP, is this still best, or oop way of handling task needing to be done based on a value. i know, i'm sorry, i don't think i know enough yet to ask the question intelligently. anyway thanks again. |
James Kuyper <jameskuyper@alumni.caltech.edu>: Jun 19 08:35PM -0400 On 6/19/19 1:06 PM, Alf P. Steinbach wrote: > On 19.06.2019 16:53, jameskuyper@alumni.caltech.edu wrote: ... > specific function pointer type. This selects the corresponding overload. > On its own the name expression is ambiguous, but the context makes it > unambiguous, nice. I will concede that this seems to be a counter-example, though I would prefer to examine the precise wording that the standard uses to specify this behavior. Unfortunately, I'm having trouble locating that wording. I'm not suggesting it doesn't exist, only that I'm not sure where to look - the places I expected to find it didn't pan out. > Since it is a /condition/ it cancels the `explicit`-ness of a type's > `operator bool`. And so `cout`, say, can convert implicitly to `bool` in > that context, but not if you try to use it to just initialize a `bool`. "cout" is a primary-expression. What it means to evaluate a primary expression can be a bit tricky to discuss. My point will be a little clearer if I replace cout with a more complicated expression, such as: debug ? std::cerr : std::cout. In the if-statement if(debug ? std::cerr : std::cout) the outermost expression is a conditional expression. The fact that if() requires a type convertible to bool does not in any way affect the evaluation of the conditional expression, nor of any of it's sub-expressions. It's not until after the conditional expression has been evaluated that the context in which it has been evaluated comes in to play. That expression's result has a type of std::ostream. Only after that expression has been evaluated does it then get converted to bool. > { > const int a = foo( 3.14 ); // a = 103 > const double b = foo( 3.14 ); // b = 203.14 The evaluation of the expression foo(3.14) is completely unaffected by whether it appears as the initializer for a or the initializer for b. In either case, it constructs an object of type foo. It is only after that expression has been evaluated that the context in which it has been evaluated comes into play, determining which conversion operator is called. But that's after the evaluation of foo(3.14), and has no influence on how foo(3.14) itself is evaluated. ... |
Ian Collins <ian-news@hotmail.com>: Jun 20 02:22PM +1200 >> spreading misogynist, homophobic Christian propaganda *is* being >> hateful... > The Christian teaching is not any of those things you state. Neither is it the homophobic nonsense you and your ilk peddle. Telling people that the way they were born makes then a sinner can cause immense psychological harm. Stay on topic or bugger off. -- Ian. |
rick.c.hodgin@gmail.com: Jun 19 07:53PM -0700 On Wednesday, June 19, 2019 at 10:22:25 PM UTC-4, Ian Collins wrote: > Neither is it the homophobic nonsense you and your ilk peddle. Telling > people that the way they were born makes then a sinner can cause immense > psychological harm. The Biblical teaching is different. It's not one of condemnation, but of teaching, enlightenment, of truth. The Christian teaching is this: It's a total and complete lie of the enemy that people are born gay. It is literal demonic influence and seduction that makes people desire hurtful, sinful things of all kinds -- including homosexuality. Remove the demonic influence and the feelings toward the sinful thing literally go away. It's like losing that hurtful "friend" who's always getting you into more and more trouble. Jettison them from your life and things start turning around. That's what Jesus does at the cross. He sets you free from those demonic influences, and begins teaching you the truth about all aspects of your life. Jesus CURES people of homosexuality every day. He cures them of every spiritual corruption. He teaches them the trurh which MAKES them free. The enemy keeps people bound up by lying to them about everything. Jesus teaches only the truth about everything. That same lying enemy will tell you that Jesus is the lie. He'll exert effort to keep you believing Jesus is a joke, or a bigot, or anything else you'll believe so he can keep you away from Him, away from salvation, away from eternal life, away from Heaven. Do you like to be deceived? Do you want destroyers guiding your life? Do you want to stay on a false path leading to your soul's destruction? Or do you want to know the truth? All Jesus does is everything right. Teaching us all the while. -- Rick C. Hodgin |
Ian Collins <ian-news@hotmail.com>: Jun 20 03:08PM +1200 > Jesus CURES people of homosexuality every day. He cures them of > every spiritual corruption. He teaches them the trurh which MAKES > them free. That is a straight up lie. Your view of the world comes from a time when the science of the mind (and pretty much anything for that matter) was non-existent. Saying someone suffers from spiritual corruption for being what they are is an evil nasty thing to do. -- Ian. |
rick.c.hodgin@gmail.com: Jun 19 08:21PM -0700 On Wednesday, June 19, 2019 at 11:08:12 PM UTC-4, Ian Collins wrote: > being what they are is an evil nasty thing to do. > -- > Ian. There are real feelings involved. People really do believe many things that, from their point of view is perfectly real, legitimate, irrefutable. What God teaches us is the true nature of our existence, what we lost when sin entered in, how we're now spiritually dead and blind, and how a spiritual enemy uses that blindness and death to actively deceive us. There is total and complete victory over everything in Jesus Christ, Ian. I would never lie to you. -- Rick C. Hodgin |
Bo Persson <bo@bo-persson.se>: Jun 20 11:06AM +0200 > Why doesn't C++ allow a function overload by the return type? > Outwardly, it seems to be an arbitrary constraint. It is kind of arbitrary and other languages, like Ada, allow it. However, considering that the Overloading clause in the C++ standard http://eel.is/c++draft/over is already 30 pages long, perhaps that is complicated enough? Bo Persson |
rick.c.hodgin@gmail.com: Jun 20 05:20AM -0700 On Wednesday, June 19, 2019 at 11:08:12 PM UTC-4, Ian Collins wrote: > Saying someone suffers from spiritual corruption for > being what they are is an evil nasty thing to do. I feel this statement you've made needs addressing. People suffer from spiritual corruption because of sin. Even Adam's original sin caused us to suffer spiritually because we are actually three-fold beings just as God is: 1) God the Father ---------> soul 2) God the Son -------------> body 3) God the Holy Spirit -----> spirit When sin entered in, our soul was condemned, and our spirit (our eternal nature) died. All we have now is our body, and the life spirit that is here until we die in this world. However, our body is still capable of receiving spiritual input. God draws us to His Son by His only Holy Spirit, which moves us to come to Jesus and ask forgiveness. He does this for all people who will be saved. But there are evil spirits in this world, condemned angels who re- belled against God, who are out like street thugs and gang members trying to destroy everything they come across. Instead of breaking windows, smashing up cars, painting graffiti and terrorizing people in the neighborhood, they have a different goal. Because of what Jesus did at the cross, their goal is to keep people away from Jesus at all costs, because they know that everyone who comes to Him is SET FREE from that condemnation, and their spirit is born again, alive, made new. They use every false means possible to deceive each person. For some that means gambling. For others it means an obsession on their car, that they have to restore it to perfect condition. For some it means adultery. For some it means lying, cheating, stealing, or whatever, to "get ahead" in life. For others, it means a life intrusion, like an addiction, or homosexuality, something that takes over the normal operation of one's life and supplants it with some- thing that is away from God, and harmful to people and to the relation- ship with God. The spiritual corruption comes from our flesh being able to be moved by spiritual input. Evil spirits exert force upon our flesh to make us feel things, have emotions, have thoughts. They use their spirit abilities to make our flesh feel certain ways. They poke and they prod and they test and the examine our responses to each to see what exactly it is we will believe in. The strongest evil spirits result in addictions for people, or for homosexuality. These are the most infiltrating and damaging evil spirits, but all of them can be broken by turning to Christ, by re- penting of your sin, by asking Him to forgive you. This takes away your soul's condemnation. It means you are in a right legal standing with God (no sin). It means your spirit (your eternal nature) is able to come alive again, which changes you here in this world because now your flesh is receiving input from your own spirit! And God also comes to you and guides you by His own Holy Spirit, teaching you how to separate the truth from falseness. ----- This is not a joke, Ian. I'm not trying to deceive you so I can get you to join a cult or send me money. My goals are God's goals for your existence: to save your soul from judgment, and to see you redeemed in eternity. I ask you to consider this, to realize that we are in a pickle be- cause of sin, and that predicament had no way out (considering the nature of our eternal death by sin). God had to step in personally and make a way to take our sin away. He did this by His Son at the cross in due time, and in so doing saved all people past, present, and future, who will be saved. He takes their sin off/away from them, and transfers it onto Himself at the cross, so that when He died in this world, all our sin died with Him. And when He rose again from death on the third day, all who believed in Him rise with Him and are alive with Him forever. Consider these things, Ian. I am not lying to you. I am teaching you the truth, so that you too can be set free from sin, and so you too can gain eternal life. -- Rick C. Hodgin |
Juha Nieminen <nospam@thanks.invalid>: Jun 20 09:41AM > ordering on strings, which is a widely required feature. > And the implementation of strcmp yields ordering with zero extra cost > compared to a pure equality test. For this reason even std::string offers a compare() function that has a three-valued return value. Suppose you are, for example, doing a binary search for a particular string in an ordered array of strings. If you didn't have the three-valued comparison, you would need to do the comparison twice for the final position in order to determine if the string is actually in the array or not. With the three-valued comparison you don't need that extra comparison. |
Juha Nieminen <nospam@thanks.invalid>: Jun 20 09:35AM >> return mValue < rhs.mValue; >> } > Why should it fail? Because Data is not an inner class of AClass? |
Tim Rentsch <tr.17687@z991.linuxsc.com>: Jun 19 10:19PM -0700 >> } position; // a structure variable >> when would something where the tag is omitted be useful? > It is never useful to omit the tag, [...] In C it can be useful to omit a tag, if one wants to ensure that the type is not used anywhere else in the program, or simply make it evident that the type will not be used anywhere else in the program. That reasoning doesn't apply in C++, because of decltype. |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 20 12:56AM >this behavior. Unfortunately, I'm having trouble locating that wording. >I'm not suggesting it doesn't exist, only that I'm not sure where to >look - the places I expected to find it didn't pan out. It might be: 11.4 Address of overloaded function [over.over] in n4800. The examples in p5 seems to hint at this. However, where exactly is the type-match wording? I'm not sure. Maybe, |A function with type F is selected for the function type FT |of the target type required in the context if F is identical |to FT. ? |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment