Re: [Vala] type MIN and MAX



I dont really need it, but if you read the thread some mails up (and
old :P) you will see the common problem of passing an invalid format for
a var type. And having an automatic type-format definition for vala. and
make it generate the proper one for glibc depending on the type would be
nice:

On Mon, 2008-09-15 at 08:32 -0400, Levi Bard wrote:
What about this?

http://blog.stevex.net/index.php/string-formatting-in-csharp/

Just taking {0} {1}...

What would the c#-style format give us that the printf-style doesn't?
If you're just going to use an item's to_string() method, you can
invoke it explicitly and use %s.
The c#-style formatting has the additional pitfall of letting you
inadvertently do:  string.Format("{0} blah {1}", foo);
I see a fair number of those, and they don't get caught until runtime.

you can easily detect this at compile time with vala. and actually is
what it does. so in vala, you are forced to give to a format string the
proper number of arguments.

btw in C it is also possible to access the arg0, arg1, arg#, but you
have to specify the type.

f.ex:

| using GLib;
| public class Main : Object {
|  static int main (string[] args) {
|   stdout.printf ("uint.min    => %u\n", uint.MIN);
|   stdout.printf ("uint.max    => %u\n", uint.MAX);
|   stdout.printf ("ulong.min   => %lu\n", ulong.MIN);
|   stdout.printf ("ulong.max   => %lu\n", ulong.MAX);
|   stdout.printf ("uint32.min  => %lu\n", uint32.MIN);
|   stdout.printf ("uint32.max  => %lu\n", uint32.MAX);
|   stdout.printf ("int64.min   => %lld\n", int64.MIN);
|   stdout.printf ("int64.max   => %lld\n", int64.MAX);
|   stdout.printf ("uint64.min  => %llu\n", uint64.MIN);
|   stdout.printf ("uint64.max  => %llu\n", uint64.MAX);
|  }
| }

So. changing the type of a variable from int32 to int64 will fix all the
format strings in a single hit. I found this useful..



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]