LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-30-2013, 12:57 PM   #1
Aqua_Regia
Member
 
Registered: Oct 2011
Posts: 37

Rep: Reputation: Disabled
Error with vector addition code


I have been trying to get this code to compile but I keep getting the error. "error: expected declaration specifiers or ‘...’ before ‘*’ token" Please see the code below. I am using gcc 4.8.1

Code:
#include<stdio.h>
#include<stdlib.h>

#define N   1000000000

void add( *a, *b, *c ) {
    int tid = 0;    // this is CPU zero, so we start at zero                                                                                           
    while (tid < N) {
        c[tid] = a[tid] + b[tid];
        tid += 1;   // we have one CPU, so we increment by one                                                                                         
    }
}

int main( void ) {
double *a = malloc(N*sizeof(double));
double *b = malloc(N*sizeof(double));
double *c = malloc(N*sizeof(double));

    // fill the arrays 'a' and 'b' on the CPU                                                                                                          
    for (int i=0; i<N; i++) {
        a[i] = rand();
        b[i] = rand();
    }

    add( a, b, c );

        free(a);
        free(b);
        free(c);
    return 0;
}

Last edited by Aqua_Regia; 10-30-2013 at 12:58 PM.
 
Old 10-30-2013, 08:22 PM   #2
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
void add( double *a, *b, *c )

(You probably also need an extra level of indirection).
 
Old 11-05-2013, 05:45 AM   #3
ArnavKumar
LQ Newbie
 
Registered: Oct 2013
Posts: 5

Rep: Reputation: Disabled
That's why i dont use C..
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] vector,matrices drawing software. some thing like android(Visual Vector Math) PoleStar Linux - Newbie 3 11-02-2012 10:45 PM
double addition error kanakkuDev Programming 4 11-16-2010 09:27 PM
LXer: Tropic of Vector – a blog devoted to Vector Linux Light, plus the Vector Linux LXer Syndicated Linux News 0 09-17-2009 01:30 PM
amcheck error while addition of w2k3 server as client raktri4u Linux - Newbie 6 03-13-2009 10:56 AM
C++ adding an extra vector stops code from working timhardy Programming 4 08-17-2005 07:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration