Thread: error including undeclared structure

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    222

    error including undeclared structure

    Hi,

    please help. I am again abusing c. so i get this error :

    stra.c:54:29: error: ‘PS_index’ undeclared (first use in this function)

    and the function is

    PS_Index = function(PS_index, indexData);

    so what i am trying to do is :

    first file:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #include "stra.h"
    
    int main (){
    
    char name[] = "index.pif";
    uint32_t i = 0;
    i= funcIndex (name);
    
    return 0;
    
    }
    second file

    Code:
    #include "stra.h"
    
    struct StraIndex *PS_Index = NULL;
    
    funcIndex(char * name){
    
    PS_Index = func(PS_index, indexData);
    
    }
    and header file:

    Code:
    typedef struct StraIndex{
    	uint32_t s;
    	uint32_t *i;
    	uint32_t *t;
    }StraIndex;
    so first i would like to create my stra.o so i compile it as :

    gcc -c stra.c -o stra.o

    and then i get the above error. What would be the proper way to get a global structure inside my object. is that possible or did i misunderstood something.

    thnx

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    The second file
    Code:
    #include "stra.h"
     
    struct StraIndex *PS_Index = NULL;
     
    funcIndex(char * name){        <-- Here you need as return type void, but this is not an error, since the default is int.
     
    PS_Index = func(PS_index, indexData);   <-- ERROR! Where did you define/declare a function with the name "func"???
     
    }
    Ok, you want a return type int (now I saw your main).
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    The error (which he has probably already discovered by now) is simply a misspelling of your variable. It's PS_Index, not PS_index (uppercase not lowercase I).

    So you didn't actually post the code you wanted us to check. Instead, you made up and posted some other code. Always post either the original code that actually has the error (the code you posted does not), or, if the program is large, create a small program that still demonstrates the problem.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'a' undeclared (first use in this function) Error
    By critixal in forum C Programming
    Replies: 3
    Last Post: 07-02-2013, 06:31 PM
  2. Undeclared Variable Error
    By greendragons in forum C Programming
    Replies: 8
    Last Post: 12-21-2011, 08:48 AM
  3. error: ‘numberOfElements’ undeclared
    By leahknowles in forum C Programming
    Replies: 6
    Last Post: 03-23-2011, 08:58 AM
  4. error: undeclared (need some help)
    By Nadril in forum C++ Programming
    Replies: 17
    Last Post: 02-22-2008, 12:59 PM
  5. Compiler error error C2065: '_beginthreadex; : undeclared identifier
    By Roaring_Tiger in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2003, 01:54 AM