⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typeof.jc

📁 The JILRunOnly project is a simple command-line application written in ANSI-C that is intended to de
💻 JC
字号:
/*
 *	typeof.jc
 *
 *	In this file we test the typeof operator, which allows us to determine the
 *	actual type of a variable or expression during compile time, as well as during run time.
 *	This is especially helpful when using the typeless var type.
 */

/*
 *	Forward declarations and imports
 */

import stdlib;
import File;

/*
 *	function main
 */

function string main()
{
	var c = new File();					// allocate a File object and assign it to a typeless var
	var d = new Foo();					// allocate a Foo and assign it to another var

	PrintType( "null", null );
	PrintType( "27", 27 );
	PrintType( "27.5", 27.5 );
	PrintType( "\"hello\"", "hello" );
	PrintType( "{1, 1}", {1, 1} );
	PrintType( "c", c );
	PrintType( "d", d );

	return "";
}

/*
 *	function PrintType
 */

function PrintType( string name, var t )
{
	switch( typeof(t) )
	{
		case typeof(null):
			stdlib::Printf("argument '%s' is of type 'null'\n", name );
			break;
		case typeof(long):
			stdlib::Printf("argument '%s' is of type 'long'\n", name );
			break;
		case typeof(float):
			stdlib::Printf("argument '%s' is of type 'float'\n", name );
			break;
		case typeof(string):
			stdlib::Printf("argument '%s' is of type 'string'\n", name );
			break;
		case typeof(array):
			stdlib::Printf("argument '%s' is of type 'array'\n", name );
			break;
		case typeof(File):
			stdlib::Printf("argument '%s' is of type 'File'\n", name );
			break;
		case typeof(Foo):
			stdlib::Printf("argument '%s' is of type 'Foo'\n", name );
			break;
	}
}

/*
 *	class Foo
 *
 *	For testing classes, we create a little useless Foo class
 */

class Foo { method Foo(){} }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -