Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 403
    • Issues 403
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Issues
  • #1166
Closed
Open
Created Jul 10, 2014 by Artem Shinkarov@temaOwner

Typecasting fails

Bugzilla Link 1124
Created on Jul 10, 2014 17:57
Version svn
OS Linux
Architecture PC
Attachments feedsmall, rgb.sac, program.sac

Extended Description

Here is an experiment:
We define a type called rgb in the module called rgb.sac like this:
$ cat -n rgb.sac
     1	module rgb;
     2	
     3	export all;
     4	typedef int[3] rgb;
     5	
     6	int[.] shape (rgb[.,.] a)
     7	{
     8	  return Array::drop ([Array::- 1], Array::shape ((int[.,.,.])a));
     9	}
We also define the shape function.
Now the main progam looks like this:
$ cat -n program.sac 
     1	use String: {string};
     2	use BMP: all;
     3	use rgb: all;
     4	
     5	rgb[.,.] my_readBMP( string name)
     6	{
     7		img = BMP::readBMP( name);
     8		StdIO::print (Color8::shape (img));
     9		b = (int[.,.,.])img;
    10		StdIO::print (Array::shape (b));
    11		a = (rgb[.,.])b;
    12		StdIO::print (shape (a));
    13		return a;
    14	}
    15	
    16	int main()
    17	{
    18		img = my_readBMP("feedsmall.bmp");
    19		StdIO::print (shape (img));
    20		return 0;
    21	}
and the output of the program is this:
$ ./a.out 
Dimension:  1
Shape    : <  2>
<10 10 > 
Dimension:  1
Shape    : <  3>
<10 10  3 > 
Dimension:  1
Shape    : <  0>
<>
Dimension:  1
Shape    : <  3>
<10 10 22851456 > 
So, as you can see, the shape information after the typecast to rgb[.,.] type is wrong.  If we inline the shape in rgb, the problem goes away.  If we introduce object references inside the shape, the problem goes away:
int[.] shape (rgb[.,.] a)
{
  sh= Array::drop ([Array::- 1], Array::shape ((int[.,.,.])a));
  StdIO::print (sh);
  return sh;
}
O_o
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking