|
From: Per W. <pw...@ia...> - 2003-03-05 08:04:41
|
One more thing. I haven't a standard available right now, and a preliminar google only picked up an old -97 preliminary C++ standard. There you have your multicharacter literals in chapter 2 lexical conventions. http://anubis.dkuug.dk/jtc1/sc22/open/n2356/ /Per W On Wed, 5 Mar 2003, Per Westermark wrote: > The next step of from the 32-bit case statement below would be to use a > hash table. > > However, how would you replace the switch statement with std::bitset? > > /Per W > > On Wed, 5 Mar 2003, Ioannis Vranos wrote: > > > -------Original Message------- > > > > From: Per Westermark > > Date: =D4=E5=F4=DC=F1=F4=E7, 5 =CC=DC=F1=F4=E9=EF=F2 2003 12:26:51 =F0= =EC > > To: Giligun > > Cc: C++ > > Subject: Re: [Dev-C++] Character variables > > > > short s =3D 'ab'; > > int i =3D 'abcd'; > > > > given that int is 4 byte. > > > > > > =3D=3D> That isn't valid C++. And where it gets compiled you can't cons= ider it > > as safe. > > > > > > > > But a lot of compilers will give you warnings, since it you can't be su= re > > if memcpy(buf,&s,sizeof(s)) will give you > > buf[0] =3D 'a', buf[1] =3D 'b'; > > or > > buf[0] =3D 'b', buf[1] =3D 'a'; > > > > In short - be very careful about using this feature. One place where it= 's > > elegant to use is if you are reading a tagged file, where each tag is > > 4-byte long: > > char *buf; > > > > int tag =3D 0; > > for (i =3D 0; i < 4; i++) { > > tag =3D (tag << 8) | *buf++; > > } > > > > > > =3D=3D> Too system dependent. Why don't you use wchar_t instead? But si= nce he > > wants to store characters (assuming in the range 0-127) he can use a ch= ar > > sequence nicely and easily. > > > > switch (tag) { > > case 'STRT': ...; break; > > case 'HEDR': ...; break; > > case 'DATA': ...; break; > > case 'ENDF': ...; break; > > } > > > > If there are a lot of tags, the result is a very fast matching of the > > tags. > > > > > > =3D=3D> By the way i would do something like the above using std::bitse= t. > > > > > > > > Ioannis Vranos > > > > * Programming pages: http://www.noicys.freeurl.com > > * Alternative URL: http://run.to/noicys > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Etnus, makers of TotalView, The debugg= er > for complex code. Debugging C/C++ programs can leave you feeling lost and > disoriented. TotalView can help you find your way. Available on major UNI= X > and Linux platforms. Try it free. www.etnus.com > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |