Pointer to struct How create a typedef?

Hi,

I’m a new CUDA programmer. The following code can be done in C but I get an error with nvcc.

typedef struct {
unsigned long nn;
} myS;
typedef struct myS* mySPtr; /* error: invalid redeclaration of type name “myS” */

nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2010 NVIDIA Corporation
Built on Thu_Nov__4_13:45:48_PDT_2010
Cuda compilation tools, release 3.2, V0.2.1221

Any ways to do this?
Thanks!

try typedef myS* mySPtr;

Thanks for the fast response!

My problem, as stated, is fixed as you suggested.

However, if I want to put typedef myS* mySPtr1; into a header file, how would I do it?

Is it possible? I don’t want myS to be in the header. In C, I can put the line with the

error into the header file and all works.

typedef myS* mySPtr1; /* not ok here. How put this in header file? */

typedef struct {

  unsigned long nn;

} myS;

//typedef struct myS* mySPtr; /* error: invalid redeclaration of type name “myS” */

typedef myS* mySPtr2; /* ok here */

The reason there is a difference between CUDA and C here is because CUDA processes the code according to C++ rules. g++ gives an essentially identical error to CUDA:

typedef.cpp:8: error: using typedef-name ‘myS’ after ‘struct’
typedef.cpp:6: error: ‘myS’ has a previous declaration here
typedef.cpp:8: error: invalid type in declaration before ‘;’ token

I am not sure what the use case is, but maybe the following approximates what is desired? In a header file typedef.h, put

typedef struct list_node *node_ptr;

Then in a program typedef.cpp, we use this as follows:

#include <stdlib.h>

#include <stdio.h>

#include "typedef.h"

typedef struct list_node node;

struct list_node {

    unsigned long nn;

    node_ptr next;

};

int main (void)

{

    node foo;

    node_ptr bar;

foo.nn = 0xfeedbeefL;

    bar = &foo;

    foo.next = bar;

    printf ("bar=%p  bar->nn=%lx  bar->next=%p\n", bar, bar->nn, bar->next);

    return EXIT_SUCCESS;

}

Perfect :) Thanks for the help!

The following is my working example. From it, I can see that the struct needed to be explicitly named rather than anonymous.

typedef struct myNamedS* myNamedSPtr1;

   typedef struct myNamedS* myNamedSPtr2;

   struct myNamedS {

      unsigned long nn;

   };

   typedef struct myNamedS* myNamedSPtr3;

Thanks again!