View unanswered posts | View active topics It is currently Sun Jul 22, 2018 6:25 pm






Reply to topic  [ 3 posts ] 
RobotC 4.27 Pointer bad syntax? or bug? 
Author Message
Rookie
User avatar

Joined: Fri Aug 24, 2012 8:28 pm
Posts: 6
Post RobotC 4.27 Pointer bad syntax? or bug?
Hello, came across something today, was curious if I was just doing something stupid or if there is a bug here. (On RobotC 4.27 for VEX)

Code:
int* foo(int* f)
{
   return f;
}

task main()
{
  int x = 65;
  int* ptrx = &x;
 
  int x2 = *foo(ptrx);
}


This code doesn't compile with the following error:
Quote:
11: *Warning*:Internal Compiler: '*' (Pointer dereference) operator is not valid at this point
11: **Severe*:Internal -- trying to emit for undefined variable


Shouldn't foo return a pointer that I could then dereference?

The following code works:

Code:
int* foo(int* f)
{
   return f;
}

task main()
{
  int x = 65;
  int* ptrx = &x;
 
  int* ptrx2 = foo(ptrx);
  int x2 = *ptrx2;
}


Is this not allowed in C? Is there something silly I'm missing? Is this a bug in RobotC? Curious what others think. The hope is to be able to return a pointer of an arbitrary type in one line.


Mon Apr 13, 2015 1:22 am
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: RobotC 4.27 Pointer bad syntax? or bug?
I just tested your first bit of code with gcc and it works OK:
Code:
xander@ubuntu:~$ cat pointerissue.c
#include <stdio.h>

int* foo(int* f)
{
   return f;
}

void main()
{
  int x = 65;
  printf("x: %d\n", x);
  int* ptrx = &x;
 
  int x2 = *foo(ptrx);
  printf("x2: %d\n", x2);
}
xander@ubuntu:~$ ./pointerissue
x: 65
x2: 65
xander@ubuntu:~$

I'll let the compiler guy know. For now just use the method in the second blob of code you made.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Apr 13, 2015 1:41 am
Profile WWW
Rookie
User avatar

Joined: Fri Aug 24, 2012 8:28 pm
Posts: 6
Post Re: RobotC 4.27 Pointer bad syntax? or bug?
Quote:
I'll let the compiler guy know. For now just use the method in the second blob of code you made.


Thanks for the speedy reply! :D I'll use the second method for now.


Mon Apr 13, 2015 2:19 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.