.net - C# fundamentally not portable? -
i've been using c# while, , have started working on adding parallelism side project of mine. so, according microsoft, reads , writes ints , floats atomic
i'm sure these atomicity requirements workout fine on x86 architectures. however, on architectures such arm (which may not have hardware floating point support), seems these guarantees hard.
the problem made more significant fact 'int' 32-bits. there many embedded devices can't atomically perform 32-bit write.
it seems fundamental mistake in c#. guaranteeing atomicity of these data types can't done portably.
how these atomicity guarantees intended implemented on architectures there no fpus or 32-bit writes?
there 2 issues regard "portability":
- can practical implementation of language produced various platforms
 - will program written in language expected run correctly on various platforms without modification
 
the stronger guarantees made language, harder port various platforms (some guarantees may make impossible or impractical implement language on platforms) more programs written in language work without modification on platform support exists.
for example, lot of networking code relies upon fact (on platforms) unsigned char 8 bits, , 32-bit integer represented 4 unsigned chars in ascending or descending sequence. i've used platform char 16 bits, sizeof(int)==1, , sizeof(long)==2. compiler author have made compiler use bottom 8 bits of each address, or have added lot of code writing 'char' pointer shift address right 1 bit (saving lsb), read address, update high or low half based upon saved address lsb, , writing back. either of approaches have allowed networking code run without modification, have impeded compiler's usefulness other purposes.
some of guarantees in clr mean impractical implement in platform atomic operation size smaller 32 bits. what? if microcontroller needs more few dozen kbytes of code space , ram, cost differential between 8-bit , 32-bit pretty small. since nobody's going running variation of clr on part 32k of code space , 4k of ram, cares whether such chip satisfy guarantees.
btw, think useful have different levels of features defined in c spec; lot of processors, example, have 8-bit chars can assembled longer words using unions, , there lot of practical code exploits this. define standards compilers work such things. see more standards @ low end of system, making language enhancements available 8-bit processors. example, useful define overloads function can take run-time-computed 16-bit integer, 8-bit variable, or inline-expanded version constant. often-used functions, there can big difference in efficiency among those.
Comments
Post a Comment