Results 1 to 3 of 3

Thread: Simba const-ness

  1. #1
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default Simba const-ness

    How can I declare a constant array as the return type? Or constant pointer to constant data?

    I tried:

    Simba Code:
    Function Foo: const array[0..2] of integer; //does not compile.
    var
      myarr: array[0..2] of Integer = [2, 5];
    begin
      result := myarr;
    end;

    begin
      Foo[0] := 10; //should fail. Result is constant.
    end.

    Simba Code:
    const
      arr = ['1', '2'];

    Function Foo: ^char;
    begin
      Result := @arr[0];  //can't.. expected variable..
    end;

    Function Foo2: const ^char; //can't..
    begin
      Result := @arr[0];
    end;

    I know you can do this:

    Simba Code:
    type
      PInt = ^Integer;

    const
      Foo = PInt(100);

    but why is there no way to have const return types?

    Even this fails:
    Simba Code:
    type pInt = ^Integer;

    Function Foo: PInt;
    var
      I: Integer;

    const
      Res: PInt := (@I);
    begin
      I := 10;
      result := Res;
    end;

    const
      I: PInt := Foo;
    begin
      I^ := 20; //biggest wtf..

      writeln(I^); //prints 20 -__-
    end.


    Is there seriously no way to have data and pointed to data immutable? I want to have a const pointer. One that cannot be written to or even immutable pointers that cannot be changed once initialized..

    Impossible?
    Last edited by Brandon; 02-24-2014 at 02:09 AM.
    I am Ggzz..
    Hackintosher

  2. #2
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Wow @ that "biggest wtf" script...

    Simba Code:
    const
      a := 1;

    begin
      @a; // Variable expected, like OP's script also tells us
    end.

    Yeah, I'm lost here as well. @nielsie95;?

  3. #3
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Sorry for the late response!
    Only a value can be immutable, not a type. This is not possible in Pascal.
    Hup Holland Hup!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •