problem about ctype-Collection of common programming errors


  • Alex Essilfie
    vb.net casting directcast ctype
    Ever since I moved from VB6 to VB.NET somewhere in 2005, I’ve been using CType to do casting from one data type to another. I do this because it is simply faster to type, used to exist in VB6 and I do not know why I have to be using DirectCast if there is apparently no difference between them.I use TryCast once in a while because I understand that sometimes casting can fail. I however cannot get the difference between CType and DirectCast.Can anyone tell me the difference in plain simple English

  • Brij
    .net vb.net ctype
    In VB.NET CType can be used to convert one type to another.CType(expression,type)I have the “expression” stored in an instance object class, say “objExp”. I have the “type” stored in an instance of Type class, say”objType”.I am trying CType(objExp, objType) I am getting compile error, how should I go about it ? “objType” is fetched and assigned at runtime.

  • J. Steen
    vb.net casting ctype
    I would like to be able to cast a value dynamically where the type is known only on runtime. Something like this:myvalue = CType(value, “String, Integer or Boolean”)The string that contains the type value is passed as argument and also read from a database, and the value is stored as string in the databaseIs this possible?

  • user1655331
    vb.net ctype dynamictype
    I would like to know if this is ok, lets say I have a class somewhere on my project and at some point I will need to cast an object to this class type or another but I can only know this at runtime, so at design time can I do something like this??Dim obj = ‘will be assigned something of some type. Dim typeObj As Type = Type.GetType(“xxxx.Foo”) Dim fooVar As Foo = CTypeDynamic(obj, typeObj)will this work as lets says:Dim x As String = “3” Dim n As Integer = CType(x, Integer)

  • Elite Mx
    c99 integer-overflow ctype
    What is the proper way to deal with character values which when casted to an unsigned char fall between {INT_MAX + 1 … UCHAR_MAX} where UCHAR_MAX is greater than INT_MAX.int is_digit(char c) {unsigned char uchar = c;if(uchar > INT_MAX)return MAYBE;return isdigit((int)uchar) ? YES : NO; }

  • Jens
    c compiler-warnings ctype
    I have the following code to read an argument from the command line. If the string is 1 character long and a digit I want to use that as the exit value. The compiler gives me a warning on the second line (array subscript has type ‘char’ ) This error comes from the second part after the “&&” .if (args[1] != NULL) {if ((strlen(args[1]) == 1) && isdigit(*args[1]))exit(((int) args[1][0]));elseexit(0);} }Also, when I use a different compiler I get two errors on the next line (exit)

  • jamesdlin
    c ctype
    The various is… functions (e.g. isalpha, isdigit) in ctype.h aren’t entirely predictable. They take int arguments but expect character values in the unsigned char range, so on a platform where char is signed, passing a char value directly could lead to undesirable sign extension. I believe that the typical approach to handling this is to explicitly cast to an unsigned char first.Okay, but what is the proper, portable way to deal with the various isw… functions in wctype.h? wchar_t, like c

  • Shafik Yaghmour
    c c11 ctype
    Traditionally, it was strictly speaking an error to pass a signed char to the ctype.h predicates because they were only defined for -1 to 255, so -128 to -2 could end up reading outside array bounds.Was this ever fixed, or do you still strictly speaking have to use unsigned char to avoid undefined behavior in modern versions of C?

Web site is in building