problem about type-safety-Collection of common programming errors
Vilhelm Gray
c casting type-conversion c99 type-safety
I have a char array holding several characters. I want to compare one of these characters with an unsigned char variable. For example:char myarr = { 20, 14, 5, 6, 42 }; const unsigned char foobar = 133;myarr[2] = foobar;if(myarr[2] == foobar){printf(“You win a shmoo!\n”); }Is this comparison type safe?I know from the C99 standard that char, signed char, and unsigned char are three different types (section 6.2.5 paragraph 14).Nevertheless, can I safely convert between unsigned char and char, and back, without losing precision and without risking undefined (or implementation-defined) behavior?In section 6.2.5 paragraph 15:The implementation shall define char to have the same range,representation, and behavior as either signed char or unsigned char.In section 6.3.1.3 paragraph 3:Otherwise, the new type is signed and the value cannot be represented in it; either the result is impl
sharptooth
c++ enums types type-safety
With the following C++ definitions:enum EnumA {EA_Element = 1 };enum EnumB {EB_Element = 10 };the following code won’t com
troutwine
Fishtoaster
type-systems type-safety weak-typing
This came up in a discussion with a f
igaar
javascript data type-safety
Because of the need constantly arising on detecting data types, and I have written the following function that so far has served well, so I would like to share the code with you. However I’m beginning to think that this maybe isn’t an efficient way for type detection.function detectType(data) {// analyze data to distinguish object types from primitive typesvar dataType = typeof data;var toClass = {}.toString; // this is used to detect object typesvar isPrimitive;var isFalsy = false;switch(dataType) {case ‘string’:isFalsy = !data;if(isFalsy) {dataType = ’empty string’; // Only if you want to distingush
aaronasterling
type-safety language-theory turing-complete
My understanding is that it means that one can potentially write a program to formally prove that a program written in a statically typed language will be free of a certain (small) subset of defects.My problem
Jeff Axelrod
Paul
c++ c++11 variadic-templates type-safety
There are several implementations of variadic templates printf function. One is this:void printf(const char* s) {while (*s) {if (*s == ‘%’ && *++s != ‘%’) throw std::runtime_error(“invalid f
Prasoon Saurav
Paul Manta
c# c++ type-safety
I was reading through the questions with most votes from the history tag and
nponeccop
Mechanical snail
c pointers casting function-pointers type-safety
I’m just beginning to wrap my head around function pointers in C. To understand how casting of function pointers works, I wrote the following program. It basically creates a function pointer to a function that takes one parameter, casts it to a function pointer with three parameters, and calls the function, supplying three parameters. I was curious what would happen
Soroush
Hasturkun
c++ c type-safety
Possible Duplicates:What is Type-safe?What is type-safety? I was reading about
Sinan Ünür
Paweł Hajdan
php oop type-safety
PHP, as we all know is very loosely typed. The language does not require you to specify any kind of type for function parameters or class variables. This can be a powerful feature.Sometimes though, it can make debugging your script a painful experience. For example, passing one kind of object into a method that expects a different kind of object can produce error messages complaining that a certain variable/method doesn’t exist for the passed object. These situations a
GreyCat
java reflection compiler-warnings type-safety
I’m trying to use one of the simplest forms of reflection to create an instance of class:package some.common.prefix;public interface My {void configure(…);void process(…); }public class MyExample implements My {… // proper implementation }String myClassName = “MyExample”; // read from an external file in realityClass
Originally posted 2013-11-09 23:24:39.