- What does this struct line do? - 7 Updates
- Onwards and upwards - 1 Update
- :: scope resolution operator - 1 Update
- SQL filesortcc question - 3 Updates
- What practice can get speed improvement in C++? - 1 Update
- auto i:v as iterator - 1 Update
Doug Mika <dougmmika@gmail.com>: Jul 23 01:02PM -0700 Hi, I of course know about structs, but whenever I see the word "struct" I expect a certain pattern to follow (ie. the definition of a struct). So seeing this line, I am quite perplexed. What does it mean? struct std::tm * ptm = std::localtime(&tt); It is taken from the example located at: http://www.cplusplus.com/reference/mutex/timed_mutex/try_lock_until/ Thanks |
Ian Collins <ian-news@hotmail.com>: Jul 24 08:13AM +1200 Doug Mika wrote: [Please wrap your lines!] > a struct). So seeing this line, I am quite perplexed. What does it > mean? > struct std::tm * ptm = std::localtime(&tt); There are cases in C++ where some additional disambiguation is required, for example where a struct and a function have the same name. This example isn't one of them... Both "struct" and in my opinion the use of std:: are superfluous in this case. -- Ian Collins |
Vir Campestris <vir.campestris@invalid.invalid>: Jul 23 09:47PM +0100 On 23/07/2015 21:13, Ian Collins wrote: > for example where a struct and a function have the same name. > This example isn't one of them... Both "struct" and in my opinion the > use of std:: are superfluous in this case. My guess is it was written by an old C programmer, where "struct" is more often needed. Which std:: do you think is superfluous? Andy |
Victor Bazarov <v.bazarov@comcast.invalid>: Jul 23 04:58PM -0400 On 7/23/2015 4:47 PM, Vir Campestris wrote: > My guess is it was written by an old C programmer, where "struct" is > more often needed. > Which std:: do you think is superfluous? Both, probably. Regardless of how the header was included, 'struct tm' and 'localtime' function are likely declared in the global namespace anyway (as well as in 'std'). V -- I do not respond to top-posted replies, please don't ask |
red floyd <no.spam@its.invalid>: Jul 23 02:17PM -0700 On 7/23/2015 1:02 PM, Doug Mika wrote: > It is taken from the example located at: > http://www.cplusplus.com/reference/mutex/timed_mutex/try_lock_until/ > Thanks It's declaring a point to a std::tm, and initializing it with the return value from std::localtime. std::tm and std::localtime are defined in <ctime> Ian is right that the "struct" is superfluous (it's a C-ism). I believe he's wrong about the std:: being superfluous. |
Ian Collins <ian-news@hotmail.com>: Jul 24 09:45AM +1200 red floyd wrote: > std::tm and std::localtime are defined in <ctime> > Ian is right that the "struct" is superfluous (it's a C-ism). > I believe he's wrong about the std:: being superfluous. Whether the std:: is superfluous depends on whether <ctime> or <time.h> was included. <ctime> will bring the symbols form <time.h> into the std namespace. -- Ian Collins |
Bo Persson <bop@gmb.dk>: Jul 24 12:38AM +0200 On 2015-07-23 22:47, Vir Campestris wrote: >> use of std:: are superfluous in this case. > My guess is it was written by an old C programmer, where "struct" is > more often needed. Yes, it's likely a C-ism left over. In C you can write struct tm* = ... even if the header is not included, as 'struct tm' works as a forward delaration when used to declare a pointer. Not so if we add std:: to it. Bo Persson |
woodbrian77@gmail.com: Jul 23 03:21PM -0700 On Friday, July 3, 2015 at 4:59:01 PM UTC-5, Öö Tiib wrote: > I think you are OK and all ... but I do not even see what is the > significance of your data serialization/deserialization/transfer utility > compared to any other similar thing. It's an on line alternative. Brian Ebenezer Enterprises - In G-d we trust. http://webEbenezer.net |
red floyd <no.spam@its.invalid>: Jul 17 10:08AM -0700 On 7/17/2015 9:52 AM, Doug Mika wrote: > I have been reading about C++ for a while, but I must admit, that one of the things that I find confusing is all the instances when you use the scope resolution operator ::. Namespaces, inheritence, etc... > So it begs the question, when we write vector<int>::const_iterator myIterator > can I deduce from this that const_iterator is an inner class of vector<int> class? Is it? No. It is a *typename* that is defined within vector<int>. It is not necessarily an inner class. Example: class A { public: typedef int integral_type; }; A::integral_type x = 0; x is of type int. |
Ian Collins <ian-news@hotmail.com>: Jul 17 09:24AM +1200 The Doctor wrote: > All right next hurdle: > Script started on Thu Jul 16 13:58:08 2015 > doctor.nl2k.ab.ca//usr/source/mysql-5.6.25$ gmake <snip> > [31m [1mLinking CXX executable mysqld > [0mlibsql.a(handler.cc.o): In function `get_ha_partition(partition_info*)': > /usr/source/mysql-5.6.25/sql/sql_alloc.h:30: undefined reference to `ha_partition::ha_partition(handlerton*, partition_info*)' This link error takes you out of the C++ language domain and into MySQL land. You'll have more luck getting answers on a MySQL forum or group than here. -- Ian Collins |
doctor@doctor.nl2k.ab.ca (The Doctor): Jul 16 08:15PM >Yeah, it is only 12 years old. :-) >Bo Persson It still works. Anyone for GCC 2.95 ? All right next hurdle: Script started on Thu Jul 16 13:58:08 2015 doctor.nl2k.ab.ca//usr/source/mysql-5.6.25$ gmake [ 0%] Built target INFO_BIN [ 0%] Built target INFO_SRC [ 3%] Built target strings [ 10%] Built target mysys [ 10%] Built target dbug [ 10%] Built target mysys_ssl [ 10%] Built target comp_err [ 10%] Built target GenError [ 10%] Built target blackhole [ 10%] Built target blackhole_embedded [ 10%] Built target archive [ 10%] Built target archive_embedded [ 10%] Built target federated [ 10%] Built target federated_embedded [ 12%] Built target myisammrg [ 14%] Built target myisammrg_embedded [ 15%] Built target slave [ 15%] Built target gen_lex_hash [ 15%] Built target GenServerSource [ 15%] Built target gen_lex_token [ 15%] Built target GenDigestServerSource [ 21%] Built target perfschema [ 26%] Built target myisam [ 26%] Built target csv [ 29%] Built target heap [ 38%] Built target innobase [ 39%] Built target regex [ 40%] Built target vio [35m [1mScanning dependencies of target sql [0m[ 40%] [32mBuilding CXX object sql/CMakeFiles/sql.dir/sql_partition_admin.cc.o [0m [31m [1mLinking CXX static library libsql.a [0m[ 52%] Built target sql [ 54%] Built target binlog [ 55%] Built target rpl [ 55%] Built target master [31m [1mLinking CXX executable mysqld [0mlibsql.a(handler.cc.o): In function `get_ha_partition(partition_info*)': /usr/source/mysql-5.6.25/sql/sql_alloc.h:30: undefined reference to `ha_partition::ha_partition(handlerton*, partition_info*)' libsql.a(handler.cc.o): In function `get_ha_partition(partition_info*)': /usr/source/mysql-5.6.25/sql/mysqld.h:765: undefined reference to `ha_partition::initialize_partition(st_mem_root*)' libsql.a(sql_partition_admin.cc.o): In function `Sql_cmd_alter_table_truncate_partition::execute(THD*)': /usr/source/mysql-5.6.25/sql/sql_partition_admin.cc:822: undefined reference to `ha_partition::truncate_partition(Alter_info*, bool*)' gmake[2]: *** [sql/mysqld] Error 1 gmake[1]: *** [sql/CMakeFiles/mysqld.dir/all] Error 2 gmake: *** [all] Error 2 You have new mail in /var/mail/doctor doctor.nl2k.ab.ca//usr/source/mysql-5.6.25$ egrep exit exit Script done on Thu Jul 16 14:05:58 2015 so sql/sql_alloc.h <SNIP> /** MySQL standard memory allocator class. You have to inherit the class in order to use it. */ class Sql_alloc { public: static void *operator new(size_t size) throw () { return sql_alloc(size); } static void *operator new[](size_t size) throw () { return sql_alloc(size); } static void *operator new[](size_t size, MEM_ROOT *mem_root) throw () { return alloc_root(mem_root, size); } static void *operator new(size_t size, MEM_ROOT *mem_root) throw () { return alloc_root(mem_root, size); } static void operator delete(void *ptr, size_t size) { TRASH(ptr, size); } static void operator delete(void *ptr, MEM_ROOT *mem_root) { /* never called */ } static void operator delete[](void *ptr, MEM_ROOT *mem_root) { /* never called */ } static void operator delete[](void *ptr, size_t size) { TRASH(ptr, size); } #ifdef HAVE_purify bool dummy; inline Sql_alloc() :dummy(0) {} inline ~Sql_alloc() {} #else inline Sql_alloc() {} inline ~Sql_alloc() {}
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment