× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Larry,

> This is my dilemma: Wouldn't the documentation simply state that iconv()
> returns -1 on error, rather than (size_t)-1 if the return value could be
> negative? It seems too deliberate to decrement size_t by 1 rather than set
> it to a negative value.

The phrase "(size_t)-1" is not decrementing size_t by 1.  It is casting
-1 to a size_t type.  (If you're not a C programmer, you probably have no
idea what I meant by that.)

Basically, when you put a data type in parenthesis, and put it in front of
data, it means that you want to view that data as the type in parenthesis
instead of it's normal type.

For example:

#include <stdio.h>

int main(int argc, char **argv) {
   char *c;
   int  i = 3368413184;

   c = (char *)&i;
   printf ("%s\n", c);

   return 0;
}

What that does is create a pointer to character, and point it to an
integer field.  If you coded c = &i, you'd get a type mismatch error since
a &i is not a pointer to a character.   But, by casting it with (char *)
you're telling it to view that pointer as a pointer to a character.

Similarly, if you were to run the following code:

#include <sys/types.h>
#include <stdio.h>

int main(int argc, char **argv) {
   size_t x;

   x = (size_t)-1;
   printf("%u\n", x);

   return 0;
}

The result would be 4294967295, which is what the number -1 looks like
when viewed as an unsigned int.

(sigh) This is getting way off of topic here... I shouldn't be teaching
how to program (poorly!) in C on the RPG list.  I hope you understand what
I'm saying, now, though.

Unless your string is larger than 2gb, I recommend just returning 10I 0
instead of 10U 0.  If you do want to use 10U 0, you can, but you'll have
to check for 4294967295 to see if it's in error -- which is fine with me,
too -- the important thing is that you understand what you're doing and
why it works.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.