c++ - Is 'avct' a legal long value or a legal var/const? -


i'm reading source code of avchat. it's video chat program using udp , directshow. in header file globaldef.h, however, find definitions below:

// messages const long msg_filtergrapherror = 'avct' + 1; const long msg_mediatypereceived    = 'avct' + 2; const long msg_tcpsocketaccepted    = 'avct' + 3; const long msg_udpcommandreceived   = 'avct' + 4; const long msg_modifyfiltergraph    = 'avct' + 5;  // let main thread modify filter graph #define wm_modifyfiltergraph        (wm_user+123)  // udp command defines const long max_command_size     = 100; const long cmd_clientcalling    = 'avct' + 100; const long cmd_deviceconfig     = 'avct' + 101; const long cmd_buildfiltergraph = 'avct' + 102; const long cmd_disconnectrequest    = 'avct' + 103; 

i thought '' used surround single char, why code runs without problem on vs2010? these long consts used commands sent client server. i've set breakpoint watch value, , vs tells me 'avct' = 1635148660. i've tried search 'avct' in entire solution , find no match except these. please tell me how value of 'avct' generated.

edit: find if put multiple characters between '' , feed char variable, last character transferred. can explain why 'avct' won't report error, still don't know how value generated.

historically, original c accepted multi-character character constants, , both c , c++ still do, on historical grounds. unlike single character constants, type int, , value implementation defined (but typically consist of sort of combination of characters involved).

practically speaking, should avoided in new code, , cannot used in portable code (because implementations vary mean).

edit:

for it's worth: typical implementation more or less equivalent of:

union {     char c[sizeof(int)];     int i; }; 

, placing characters in order in c (and ignoring didn't fit—whether first or last depending on implementation), , use value of i value. these results depend on encoding (but that's true of character constant), on things byte order , size of int. thus, assuming ascii based encoding, on systems i've used, results 0x61766374, 0x74637661, 0x6374, 0x7463, 0x6176 or 0x7661. (and doesn't consider "exotic" architectures 9 bit bytes, or size of int 6.)


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -