So I have a really frustrating build error I have been staring at for the past hour or two. It involves one of my functions in my linked list program. It thinks I have statements outside the function when they are clearly inside, and thinks the { : } ratio is off. Am I missing something really simple?
// Index returns the location of element e. If e is not present,
// return 0 and false; otherwise return the location and true.
func (list *linkedList) Index(e AnyType) (int, bool) {
var index int = 0
var contain bool = false
if list.Contains(e) == false {
return 0, false
}
for int i := 0; i < list.count; i++ { \\175
list.setCursor(i)
if list.cursorPtr.item == e {
index = list.cursorIdx
contain = true
}
}
return index, contain \\182
} \\183
Build errors
./lists.go:175: syntax error: unexpected name, expecting {
./lists.go:182: non-declaration statement outside function body
./lists.go:183: syntax error: unexpected }
I appreciate any help. Thank you.
Looks like it's all line 175's fault, should be
for i := 0; i < list.count; i++ {
note I removed int
Related
I am experimenting with the STM32f407vg board through the STMBUBEIDE program.
First of all, I prepare my own library file and make the settings in the interrupt section.
What if the reason I can't get rid of this error?
First of all, I have a griodriver.c file for my src file. And my definition in it:
uint8_t portcode = GPIO_BASE_ADDR_TO_CODE (pGPIOHandle-> pGPIOx);
Then I write my function so that this comes back.
uint16_t GPIO_BASE_ADDR_TO_CODE(*x)
{
if(x==GPIOA) { return 0; }
else if(x==GPIOB) { return 1; }
else if(x==GPIOC) { return 2; }
else if(x==GPIOD) { return 3; }
else if(x==GPIOE) { return 4; }
else if(x==GPIOF) { return 5; }
else if(x==GPIOG) { return 6; }
}
If I remove the pointer inside the loop, I get a comparison between pointer and interger error.
Whenever I compile I get an error.
My error says this for the function:
This is warnings error.
Description Resource Path Location Type
implicit declaration of function 'GPIO_BASE_ADDR_TO_CODE'; did you mean 'GPIOJ_BASEADDR'?
[- Wimplicit-function-declaration] stm32f407xx_gpio_driver.c /stm32f407xx/drivers/Src
line 253 C/C++ Problem
But there are 2 other errors I get as ERROR.
enter image description here
enter image description here
First:
1. ERROR: Description Resource Path Location Type
make: *** [drivers/Src/subdir.mk:18: drivers/Src/stm32f407xx_gpio_driver.o]
Error 1 stm32f407xx C/C++ Problem
SEcond:
Description Resource Path Location Type
expected declaration specifiers or '...' before '*' token stm32f407xx_gpio_driver.c
/stm32f407xx/drivers/Src line 168 C/C++ Problem
Error Screen:
enter image description here
When I change this part like a below,
uint16_t GPIO_BASE_ADDR_TO_CODE(uint8_t x)
{
if( x==GPIOA) { return 0; }
else if(x==GPIOB) { return 1; }
else if(x==GPIOC) { return 2; }
else if(x==GPIOD) { return 3; }
else if(x==GPIOE) { return 4; }
else if(x==GPIOF) { return 5; }
else if(x==GPIOG) { return 6; }
return 0;
}
My errors change like that :
enter image description here
Instead of calling it in a function, I defined it as #define for
GPIO_BASEADDR_TO_CODE
Also removed if else condition. I used a C third conditional.
Now is no errors after 3 days later:))
You can see it below pictures what I did.
#define GPIO_BASEADDR_TO_CODE(x) ((x == GPIOA)?0 :\
(x == GPIOB)?1 :\
(x == GPIOA)? :\
(x == GPIOA)?3 :\
(x == GPIOA)?4 :\
(x == GPIOA)?5 :\
(x == GPIOA)?6 :\
(x == GPIOA)?7 :0 )
enter image description here
I receive this error when I try to run this code:
syntax error: unexpected cornerFinder, expecting (
case "-v2":
func cornerFinder(censusData []CensusGroup) {
if len(censusData) <= 10000{
for i := 0; i <= 10000; i++ {
if (censusData.latitude > maxLat){
maxLat = censusData.latitude
}
if (censusData.latitude < minLat){
minLat = censusData.latitude
}
if (censusData.longitude > maxLong){
maxLong = censusData.longitude
}
if (censusData.longitude < minLong){
minLong = censusData.longitude
}
}
}
mid := len(data)/2
done := make(chan bool)
go func() {
cornerFinder(censusData[:mid])
done<- true
} ()
cornerFinder(censusData[mid:len(censusData)])
<-done
return
}
cornerFinder(censusData)
Its giving this error on the second line of the code:
func cornerFinder(censusData []CensusGroup) {
I think it something trivial that I am missing. Been stuck on it for a couple of hours. Help would be appreciated
Function declarations are only allowed at top level. Assign a function literal to a local variable instead.
var cornerFinder func(censusData []CensusGroup)
cornerFinder = func(censusData []CensusGroup) {
... function body from the question
}
cornerFinder(censusData)
A short variable declaration is not used here because the function calls itself recursively.
I currently have some code from here (https://github.com/jmhnilbog/Nilbog-Lib-AS2/blob/master/mx/mx/remoting/NetServiceProxy.as) which converts a function into a function. This code is shown below:
private var _allowRes:Boolean= false;
function __resolve( methodName:String ):Function {
if( _allowRes ) {
var f = function() :Object {
// did the user give a default client when he created this NetServiceProxy?
if (this.client != null) {
// Yes. Let's create a responder object.
arguments.unshift(new NetServiceProxyResponder(this, methodName));
}
else {
if (typeof(arguments[0].onResult) != "function") {
mx.remoting.NetServices.trace("NetServices", "warning", 3, "There is no defaultResponder, and no responder was given in call to " + methodName);
arguments.unshift(new NetServiceProxyResponder(this, methodName));
}
}
if(typeof(this.serviceName) == "function")
this.serviceName = this.servicename;
arguments.unshift(this.serviceName + "." + methodName);
return( this.nc.call.apply(this.nc, arguments));
};
return f;
}
else {
return null;
}
}
Basically what the code is designed to do is return a new function (returned as f) which performs the correct server operates. However, if I try and use this syntax in AS3, I get the following two errors:
Error: Syntax error: expecting semicolon before colon.
Error: Syntax error: else is unexpected.
How would I go about doing this? I know this is someone else's code, but I am trying to get the old AS1/2 mx.remoting functionality working in AS3. Cheers.
I am currently creating a SSIS program that reads data from a file, does some processing with that data, and outputs it to a OLE DB Destination task. However, everytime I run my application, I keep getting this error: "An error occurred: Index was outside the bounds of the array".I have changed my code many of times within the script task, but I still seem to be getting this error. Does anyone have any idea on what could be the problem? If so, any hints and suggestions would greatly be appreciated. Thanks.
This is my code within script task..
bool found=false;
try
{
while (Row.NextRow())
{
int Rows = 0;
int length = 0;
//int length = Row.Source.Length;
foreach (char c in Row.Source)
{
length++;
Console.Write(length);
}
while (found == false || length==0)
{
char c = Row.Source[Rows];
Rows++;
if (char.IsLetterOrDigit(c) || char.IsPunctuation(c))
{
length = length - 1;
}
else
{
while (length != 0)
{
Rows++;
if (Row.Source[Rows] != ' ')
{
Row.Source01 = Row.Source.Replace(Row.Source[Rows], ' ');
}
length = length - 1;
}
found = true;
}
}
found = false;
}
}
catch (Exception e)
{
bool pbCancel = false;
this.ComponentMetaData.FireError(0, "myScriptComponent", "An error occurred: " + e.Message, "", 0, out pbCancel);
}
}
}
Why do you think the code below does not work?
What would you change/add to make it work?
Any help is appreciated..
function TraceIt(message:String, num:int)
{
trace(message, num);
}
function aa(f:Function, ...args):void
{
bb(f, args);
}
aa(TraceIt, "test", 1);
var func:Function = null;
var argum:Array = null;
function bb(f:Function, ...args):void
{
func = f;
argum = args;
exec();
}
function exec()
{
func.apply(null, argum);
}
I get an ArgumentError (Error #1063):
Argument count mismatch on test_fla::MainTimeline/TraceIt(). Expected 2, got 1.
..so, the passed parameter (argum) fails to provide all passed arguments..
..Please keep the function structure (traffic) intact.. I need a solution using the same functions in the same order.. I have to pass the args to a variable and use them in the exec() method above..
regards
Ok, here is the solution.. after breaking my head : )
function TraceIt(message:String, num:int)
{
trace(message, num);
}
function aa(f:Function=null, ...args):void
{
var newArgs:Array = args as Array;
newArgs.unshift(f);
bb.apply(null, newArgs);
}
aa(TraceIt, "test", 1);
var func:Function = null;
var argum:*;
function bb(f:Function=null, ...args):void
{
func = f;
argum = args as Array;
exec();
}
function exec():void
{
if (func == null) { return; }
func.apply(this, argum);
}
This way, you can pass arguments as variables to a different function and execute them..
Thanks to everyone taking the time to help...
When TraceIt() eventually gets called, it's being called with 1 Array parameter, not a String and int parameters.
You could change TraceIt() to:
function TraceIt(args:Array)
{
trace(args[0], args[1]);
}
Or you could change exec() to:
function exec()
{
func.apply(null, argum[0].toString().split(","));
}
...as it appears when you pass "test", 1, you end up with array whose first value is "test,1". This solution doesn't work beyond the trivial case, though.
Change your bb function to look like this:
function bb(f:Function, args:Array):void
{
func = f;
argum = args;
exec();
}
As you have it now, it accepts a variable number of arguments, but you are passing in an array(of the arguments) from aa.