Go to Post Wow. Just wow. Never did I think the mentor built robot debate would make it on to a tv show. - ASD20 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-13-2009, 03:27 PM
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
strcat error

testing out some code, our auto looked similar to this:
Code:
 int loop=0;
while (IsAuto())
{
     char * name = strcat((char*)(++loop), " iteration");
     printf(name);
}
and I run kernel task, downloads, open console, see nothing, on ds, auto enable, and the console prints out nothing and the ds then says no comms. the RSL was solid, but we had to restart. the strcat seems to be crashing the robot, is this possible? and why?
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #2   Spotlight this post!  
Unread 03-13-2009, 03:35 PM
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,069
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: strcat error

I think you think that strcat does something that it doesn't. You can't just cast an int to a char * and expect it to work.

How about:

Code:
 int loop=0;
while (IsAuto())
{
     printf("%d iteration\n", ++loop);
}
That is the most direct way to accomplish what you want. Alternatively, here's how to do it with strcat() properly:

Code:
 int loop=0;
while (IsAuto())
{
     char msg[100]; // We can't just declare this as a "char *" without first allocating memory - 100 characters is more than enough
     strcat( msg, itoa(++loops) );
     strcat( msg, " iteration\n");
     printf("%s", msg);
}
The standard C itoa() function takes an integer and returns a C string of the printable characters.

Last edited by Jared Russell : 03-13-2009 at 03:38 PM.
Reply With Quote
  #3   Spotlight this post!  
Unread 03-13-2009, 06:15 PM
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: strcat error

ok, but why is it crashing the crio?
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #4   Spotlight this post!  
Unread 03-13-2009, 07:02 PM
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: strcat error

Quote:
Originally Posted by byteit101 View Post
ok, but why is it crashing the crio?
You're taking the loop number and treating it like a pointer , so the rio is trying to access memory at the address of 'loop', which is probably 0 or very low. Basically you're causing a segmentation fault, which probably causes your task on the rio to exit.
Reply With Quote
  #5   Spotlight this post!  
Unread 03-13-2009, 09:38 PM
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: strcat error

ahhh! that would explain that! doesn't one love the power and the unsafeness of C/C++? (there's an easy virus: ((char*)0) = "CORRUPT THIS DATA!!!!"; )
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #6   Spotlight this post!  
Unread 03-13-2009, 09:47 PM
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,033
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: strcat error

Quote:
Originally Posted by byteit101 View Post
ahhh! that would explain that! doesn't one love the power and the unsafeness of C/C++? (there's an easy virus: ((char*)0) = "CORRUPT THIS DATA!!!!"; )
Actually, if you're running as a normal process on a modern operating system, that will only crash the individual program that did the bad access. Like in Windows when you see "X has encountered a problem and needs to close... ", many times the reason it needs to close is because of bad memory accesses. On a *nix box you'll see something on the screen saying 'segmentation fault'.

Now of course, if you're running in the kernel and make a bad memory access, then the system will generally crash, since theres nothing to protect you there. Incidentally, our programs are running as a kernel module on the cRio...
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #7   Spotlight this post!  
Unread 03-13-2009, 10:37 PM
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,069
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: strcat error

Quote:
Originally Posted by byteit101 View Post
ahhh! that would explain that! doesn't one love the power and the unsafeness of C/C++? (there's an easy virus: ((char*)0) = "CORRUPT THIS DATA!!!!"; )
Pointers are a great and terrible thing. To the point that I've worked on many projects at work where the use of non-smart pointers is strictly prohibited. Simply put, 90% of us aren't smart enough to use them effectively without shooting ourselves in the foot (and I am definitely a member of that majority!)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
LebView Error -- Error 1055 occured at Property Node in FRC Create Project.vi->FRC Wi RMS11 Programming 8 12-08-2008 06:20 PM
Error in code light on, trouble finding error Bryan Herbst Programming 16 10-12-2007 09:59 PM
180:Error: syntax error help! seanl Programming 8 02-04-2007 11:31 AM
stupid Array error: Error [1300] stack frame too l Validius Programming 7 01-27-2006 10:53 AM


All times are GMT -5. The time now is 10:31 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi