type-coercion

Checking range with command line arguments

Working on a simple C program I'm stuck with an if test: int line_number = 0; if ((line_number >= argv[2]) && (line_number <= argv[4])) gcc says: cp.c:25: warning: comparison between pointer and integer cp.c:25: warning: comparison between pointer and integer What can I do to properly check the range of lines I want to deal with?...

Changing PHP type coercion

When I moved my sites to a dedicated server from HostGator, several things were broken and all are broken involving type coercion. If $_POST['var'] is 0, it is not considered to be an integer and fails a comparison with another integer. I went through and forced int types on all of those broken places on the site I found, but I'm sure ...

How to coerce type of ActiveRecord attribute returned by :select phrase on joined table?

Having trouble with AR 2.3.5, e.g.: users = User.all( :select => "u.id, c.user_id", :from => "users u, connections c", :conditions => ... ) Returns, e.g.: => [#<User id: 1000>] >> users.first.attributes => {"id"=>1000, "user_id"=>"1000"} Note that AR returns the id of the model searched as numeric but the selected user_id of...

In Ruby, how does coerce() actually work?

It is said that when we have a class Point and knows how to perform point * 3 like the following: class Point def initialize(x,y) @x, @y = x, y end def *(c) Point.new(@x * c, @y * c) end end point = Point.new(1,2) p point p point * 3 Output: #<Point:0x336094 @x=1, @y=2> #<Point:0x335fa4 @x=3, @y=6> but then, 3...

In Ruby, can the coerce() method know what operator it is that requires the help to coerce?

In Ruby, it seems that a lot of coerce() help can be done by def coerce(something) [self, something] end that's is, when 3 + rational is needed, Fixnum 3 doesn't know how to handle adding a Rational, so it asks Rational#coerce for help by calling rational.coerce(3), and this coerce instance method will tell the caller: # I know ...

A follow up on type coercion in C++, as it may be construed by type conversion

This is a follow up to my previous question. Consider that I write a function with the following prototype: int a_function(Foo val); Where foo is believed to be a type defined unsigned int. This is unfortunately not verifiable for lack of documentation. So, someone comes along and uses a_function, but calls it with an unsigned int ...