- What does this do ??? - 2 Updates
- Inheritance-type enum - 2 Updates
- OT: Association for Orthodox Jewish Scientists - 1 Update
- C - 2 Updates
- Functions and the linker - 2 Updates
"Öö Tiib" <ootiib@hot.ee>: Mar 16 04:03PM -0700 On Wednesday, 16 March 2016 19:23:51 UTC+2, Bob Langelaan wrote: > > Yes, it is aggregate so when initialized it will be default-initialized > > (so falses) to end and when not initialized then it will be uninitialized. > But in my mind an entity can only be "initialized" when it is defined. Yes, perhaps bad wording of mine. > does not initialize bArray because bArray was previously defined. > I am assuming that what is happening that the { false } value on the right of the assignment statement is being converted to a temporary std::array<bool, 100> object which is initialized to { false }. This temporary object is then assigned to bArray. > Is my assumption correct? Yes, the '{ false }' is of magic C++11 type 'std::initializer_list'. Converted from it is a temporary object of type 'std::array<bool, 100>' The "conversion" is same as initialization as aggregate and then it is assigned to 'bArray'. Actually compiler likely optimizes all the temporaries out. |
Bob Langelaan <bobl0456@gmail.com>: Mar 16 04:13PM -0700 On Wednesday, March 16, 2016 at 4:04:00 PM UTC-7, Öö Tiib wrote: > The "conversion" is same as initialization as aggregate and then it > is assigned to 'bArray'. Actually compiler likely optimizes all the > temporaries out. Thanks! I think I have it now :) |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 16 08:47PM +0100 On 16.03.2016 01:27, JiiPee wrote: > Is it possible to get a behaviour of "inherited" enum? Not quite, because with a values type the Is-A relationship goes the other way than with class inheritance, which is what you have in C++. For example, a rational number is the result of dividing one integer by another with ordinary division, like 3/4. The set of rationals includes the set of integers, like the set of animals includes the set of dogs, so an integer Is-A rational, like a dog Is-An animal. But it makes sense in C++ to have an Animal base class and a Dog derived class, because the Dog class /adds/ information and behavior, while it does not make sense in C++ to have a Rational base class and an Integer derived class, because the Rational class has more information (you need two integers to describe a rational, in general): it's ungood base. Generally the kind of relationship involved for Rational and Integer is modeled (or implemented) by value conversion, while the kind of relationship for Animal and Dog is modeled by reference conversion. But a typed enumeration is not a class, so the value conversion technique isn't applicable. This leaves us with no proper tools to apply, and so it's all about choosing some suitable compromise – slightly deficient one way or another... > So how to dynamically add elements to an enum or simulate it somehow so > that when adding a new class I do not need to touch the original enum > definition but I can add the type inside the new class. Instead of these integer identifiers you can probably use typeid. > create integer constants for each animal type in each class, but then > they would be integer type which is "weak"... I would like to have > something similar to enum or class-type. The only practical way I can see is declare the enum type centrally, with values for all possible types. Cheers!, - Alf |
Christopher Pisz <nospam@notanaddress.com>: Mar 16 05:59PM -0500 On 3/15/2016 7:42 PM, Stefan Ram wrote: > Now to add another animal »cat«, you just add > »cat.h« and run the make process. The script will > generate the new »all_animals.h«. I didn't realize grep was part of C++ Yuck! -- I have chosen to troll filter/ignore all subthreads containing the words: "Rick C. Hodgins", "Flibble", and "Islam" So, I won't be able to see or respond to any such messages --- |
woodbrian77@gmail.com: Mar 16 03:49PM -0700 > meeting this weekend. > http://www.aojs.org/ > They have existed for over 60 years. I'm blessed today to learn of a parallel organization also on American soil -- Sinai and Synapses http://sinaiandsynapses.org/ Their Mission Sinai and Synapses offers people a worldview that is both scientifically grounded and spiritually uplifting. It provides tools and language for learning and living to the millions of people who see science as their ally as they pursue personal growth and the repair of our world. Through classes, seminars, lectures, videos and writings, it helps create a vision of religion that embraces critical thinking and scientific inquiry, and at the same time, gives meaning to people's lives and helps them make a positive impact on society. It is incubated at Clal - The National Jewish Center for Learning and Leadership, which links Jewish wisdom with innovative scholarship to deepen civic and spiritual participation in American life. Their Methods Sinai and Synapses explores big questions from both religious and scientific perspectives, and achieves its mission through several programs, activities, and learning opportunities. Adult education classes, with courses such as "There Are Places I Remember: How Memory Works (And How It Doesn't)," "This is Your Brain on Judaism," "Faith in a Scientific Age," and "The Morality Stereo System: Why Liberals and Conservatives Can't Seem to Listen to Each Other." Seminars for our Sinai and Synapses Fellows, bringing together clergy and scientists to learn together from the top scholars in both the religious and scientific worlds, and then to create programs and facilitate discussions on topics such as "Are We Using Technology, or Is Technology Using Us?" ----------------------------------------------------------- This is great news. Brian Ebenezer Enterprises - In G-d we trust. http://webEbenezer.net |
ram@zedat.fu-berlin.de (Stefan Ram): Mar 16 10:40PM >1. Design an algorithm to print hello world to the screen. | | | v .---------- / print / / "h" / / / ----------- | | | v .---------- / print / / "e" / / / ----------- | | | v .---------- / print / / "l" / / / ----------- | | | v .---------- / print / / "l" / / / ----------- | | | v .---------- / print / / "o" / / / ----------- | | | v .---------- / print / / " " / / / ----------- | | | v .---------- / print / / "w" / / / ----------- | | | v .---------- / print / / "o" / / / ----------- | | | v .---------- / print / / "r" / / / ----------- | | | v .---------- / print / / "l" / / / ----------- | | | v .---------- / print / / "d" / / / ----------- | | | v .---------- / print / / " " / / / ----------- | | | v .---------- / print / / "t" / / / ----------- | | | v .---------- / print / / "o" / / / ----------- | | | v .---------- / print / / " " / / / ----------- | | | v .---------- / print / / "t" / / / ----------- | | | v .---------- / print / / "h" / / / ----------- | | | v .---------- / print / / "e" / / / ----------- | | | v .---------- / print / / " " / / / ----------- | | | v .---------- / print / / "s" / / / ----------- | | | v .---------- / print / / "c" / / / ----------- | | | v .---------- / print / / "r" / / / ----------- | | | v .---------- / print / / "e" / / / ----------- | | | v .---------- / print / / "e" / / / ----------- | | | v .---------- / print / / "n" / / / ----------- >a. Write pseudo code of your solution first. (10 pts) Dear Computer, do me a favor and please print this letter: "h"! Thank you! Dear Computer, do me a favor and please print this letter: "e"! Thank you! Dear Computer, do me a favor and please print this letter: "l"! Thank you! Dear Computer, do me a favor and please print this letter: "l"! Thank you! Dear Computer, do me a favor and please print this letter: "o"! Thank you! Dear Computer, do me a favor and please print this letter: " "! Thank you! Dear Computer, do me a favor and please print this letter: "w"! Thank you! Dear Computer, do me a favor and please print this letter: "o"! Thank you! Dear Computer, do me a favor and please print this letter: "r"! Thank you! Dear Computer, do me a favor and please print this letter: "l"! Thank you! Dear Computer, do me a favor and please print this letter: "d"! Thank you! Dear Computer, do me a favor and please print this letter: " "! Thank you! Dear Computer, do me a favor and please print this letter: "t"! Thank you! Dear Computer, do me a favor and please print this letter: "o"! Thank you! Dear Computer, do me a favor and please print this letter: " "! Thank you! Dear Computer, do me a favor and please print this letter: "t"! Thank you! Dear Computer, do me a favor and please print this letter: "h"! Thank you! Dear Computer, do me a favor and please print this letter: "e"! Thank you! Dear Computer, do me a favor and please print this letter: " "! Thank you! Dear Computer, do me a favor and please print this letter: "s"! Thank you! Dear Computer, do me a favor and please print this letter: "c"! Thank you! Dear Computer, do me a favor and please print this letter: "r"! Thank you! Dear Computer, do me a favor and please print this letter: "e"! Thank you! Dear Computer, do me a favor and please print this letter: "e"! Thank you! Dear Computer, do me a favor and please print this letter: "n"! Thank you! >b. Write the c code for your solution. (20 pts) putchar( 'h' ); putchar( 'e' ); putchar( 'l' ); putchar( 'l' ); putchar( 'o' ); putchar( ' ' ); putchar( 'w' ); putchar( 'o' ); putchar( 'r' ); putchar( 'l' ); putchar( 'd' ); putchar( ' ' ); putchar( 't' ); putchar( 'o' ); putchar( ' ' ); putchar( 't' ); putchar( 'h' ); putchar( 'e' ); putchar( ' ' ); putchar( 's' ); putchar( 'c' ); putchar( 'r' ); putchar( 'e' ); putchar( 'e' ); putchar( 'n' ); >2. Design an algorithm that takes an integer value from the user and notifies the user either this number is even or odd. .-------------------------------------------------------------------------. | take an integer value from the user | '-------------------------------------------------------------------------' | | v .-------------------------------------------------------------------------. | notify the user either this number is even or odd | '-------------------------------------------------------------------------' >a. Write pseudo code of your solution first. (20 pts) Take an integer value from the user and then notify the user either this number is even or odd. >b. Write the c code for your solution. (20 pts) take_an_integer_value_from_the_user(); notify_the_user_either_this_number_is_even_or_odd(); >3. (30pts) Write the c code of the algorithm given in the slide 18 of 03.ppt. #include <stdio.h> int main( void ) { struct s { char * val; struct s * next; }a={ "alpha", &a }; printf( "%s\n", a.val ); printf( "%s\n", a.next->val ); printf( "%s\n", a.next->next->val ); printf( "%s\n", a.next->next->next->val ); } |
ram@zedat.fu-berlin.de (Stefan Ram): Mar 16 10:44PM >program; no diagnostic required." >I suspect taking the address of a function qualifies as odr-use, so the >above program indeed contains UB. Thank you! I now have modified this teaching example of mine so as to include the definition: #include <iostream> /* ::std::cout */ #include <ostream> /* << */ #include <string> /* ::std::string */ using namespace ::std::literals; ::std::string s() {} /* this line was added 2016-03-16 */ int main() { ::std::string const s(); ::std::cout << '>' << s << "<\n"s; } |
Paavo Helde <myfirstname@osa.pri.ee>: Mar 16 09:20PM +0200 On 16.03.2016 4:41, Stefan Ram wrote: > The above program prints »1« here. > Does the above program have undefined behavior because the > function »s« is just being declared but not defined anywhere? From the standard: "Every program shall contain exactly one definition of every non-inline function or variable that is odr-used in that program; no diagnostic required." I suspect taking the address of a function qualifies as odr-use, so the above program indeed contains UB. |
legalize+jeeves@mail.xmission.com (Richard): Mar 16 10:19PM [Please do not mail me a copy of your followup] Paavo Helde <myfirstname@osa.pri.ee> spake the secret code >program; no diagnostic required." >I suspect taking the address of a function qualifies as odr-use, so the >above program indeed contains UB. [3.2 basic.def.odr] 3. "[...] A function whose name appears as a potentially-evaluated expression is odr-used if it is the unique lookup result or the selected member of a set of overloaded functions (3.4, 13.3, 13.4), unless it is a pure virtual function and its name is not explicitly qualified." Seems pretty straight-forward to me that this means that using the name of a function as a void* argument to operator<< is an odr-use of the name. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
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