- [Jesus Loves You] Dragons, Dinosaurs and the Bible - 1 Update
- Function type syntax confusion - 4 Updates
- XanaNews Statistic for comp.lang.c++. 6/1/2020 1:06:00 AM - 2 Updates
rick.c.hodgin@gmail.com: Jun 01 04:20PM -0700 On Tuesday, May 19, 2020 at 6:00:36 PM UTC-4, Mr Flibble wrote: > -- > "Snakes didn't evolve, instead talking snakes with legs changed > into snakes." - Rick C. Hodgin I write this not for Leigh Johnston, but for those who will come across this tag he adds to his posts. As I pointed out over a year ago, his quote is incorrect: https://groups.google.com/d/msg/comp.lang.c++/IlPK_A7p1Og/5cz58_tXAwAJ This quote Leigh ascribes to me is not a quote I wrote. I said this, and I explained why it is: https://groups.google.com/d/msg/comp.lang.c++/IlPK_A7p1Og/ZGjsIFZWAwAJ "A talking serpent that God later changed to remove its legs, forcing it to crawl on its belly." ----- I came across this today listening to the DTBM channel on YouTube and I wanted to post it for corroboration from someone who is not me. This is from a PhD Bible Scholar that each of you should listen to and learn from. He is such a good teacher, gentle and kind. He will guide you with a firmness within a gentleness: https://www.youtube.com/watch?v=vV8qI9Zaa0o&t=37m17s "And so when Satan snuck down there and started stalking around in the Garden of Eden, and took and inhabited a serpent, which by the way, from the Bible, serpents used to walk, and they were the most beautiful animals of all before they were cursed, and that's why [God] said, 'you're going to be in the dust for the rest of your life.' That was part of the curse on the serpent. "And you say, 'Wait a minute. How do we know this is Satan?' Because it says in the Bible in Chapter 12 of Revelation, 'The old serpent, the dragon from old, Satan.' See, he was the stalker of humanity from the very beginning." Whatever it looked like before, it was a serpent, and it was beautiful and cunning and it's why Satan targeted that creature to approach Eve. That serpent has since become a snake, but it was something markedly different before it was cursed for deceiving Eve and introducing sin. It would've been of stunningly beautiful appearance. -- Rick C. Hodgin |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 01 03:08AM +0200 On 31.05.2020 18:13, Juha Nieminen wrote: > It's still unclear to me what the difference is between the function type > syntax of the form "ReturnType(*)(ParameterTypes)" and > "ReturnType(ParameterTypes)". Ben Bacarisse has already answered this, and some of the following, but I'll try to add a higher level perspective. As he noted the * notation declares a pointer to function, while the notation without that, declares a function. Functions and function pointers are often interchangeable, just as arrays and array item pointers are often interchangeable, because * they have implicit conversion to pointer where a pointer is needed, called a type DECAY, and * the main functionality is only defined for pointers. This is understandable given the history of C designed as a kind of portable assembly language to ease the porting of Unix. In assembly language everything is done via single values and pointers. With that perspective it's the pointers that are primary, and the function and array types are only sort of helpers to type check the pointer usage (and for arrays, to allocate storage for automatic variables). For example, there is no such thing as indexing of an array: formally indexing is defined for pointers only. And for example, there is no such thing as a call of a function: the call syntax is available for pointers only. Indexing and calling works for actual arrays and functions only because of the implicit conversions to pointer. > //------------------------------------------- > using F1 = int(*)(int); > using F2 = int(int); Yes, but you can't declare a variable of type F2. If you try to then the compiler understands that as a function declaration, not a variable. Because functions are not data in C++. Or from a higher level perspective, C++ is designed to support Harvard architecture machines where code lives in a separate address space. So there is no such thing as a variable of function type. However, you can use F2 as a parameter type. Just as with an array type it then decays. The type that F2 as parameter type expresses, is a pointer. > void foo1(F1 funcPtr); // ok > void foo2(F2 funcPtr); // ok Yes, these mean exactly the same, due to the decay of the F2 type. > F1 funcPtr1 = someFunc; // ok > F2 funcPtr2 = someFunc; // error > //------------------------------------------- Yep. Here `funcPtr2` is not a pointer, it's a function. And one cannot initialize a function. > } > int someFunction(int v) { return v+1; } > //------------------------------------------- Note that this use of a function type F2 adds a third quirk: that in a declaration of a non-static member function the type changes to, not pointer, but a member function type distinct from F2. Example: ------------------------------------------------------------------------- #include <iostream> using namespace std; using F = void(int); struct Gah { int data; F func; }; void Gah::func( int x ) { cout << x << endl; } auto main() -> int { Gah().func( 666 ); #ifdef SURPRISE Gah g = {}; int* pd = &g.data; // OK. F* pf = &g.func; //! No, not same type. (void) pd; (void) pf;
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment