Thread: array of function pointers2

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    array of function pointers2

    Okay so I wasn;'t sure if where to get help since the first thread seem to go off on topics but I wanted to get help still so i tried simpliying the code to a test portion.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #define TRUE 1
    
    typedef unsigned char Uint8;
    typedef unsigned int Uint32;
    typedef struct Ethfrm_t  Ethfrm_t;
    typedef int (*FIPF)(Uint8 *, Uint32);
    
    typedef struct FIPfrm_t
    {struct FIP_Hdr* Hdr;
    } __attribute__ ((packed))FIPfrm_t;
    
    typedef struct FIP_Hdr
    {
      Uint32 Code:16;
      Uint32 Resv1:8;
      Uint32 Subcode:8;
      Uint32 DescLen;
      Uint32 DescList;
    } FIP_Hdr;
    
    FIPF FIPFunc[4][2];
    
    int FIPDiscSolicit(Uint8 *DescListPtr, Uint32 DescListLen)
    
    {
      printf("hello your in DiscSol\n");
       return (TRUE);
    }
    
    void FIPFuncInit(int i){
    	FIPFunc[0][0] = &FIPDiscSolicit;
    }
    
    FIP_Hdr * FIPHdrProcessing(FIP_Hdr *hdr)
    {
        Uint32 DescListLen;
        Uint8  *DescListPtr;
        DescListLen = (Uint32) hdr->DescLen;
        DescListPtr = (Uint8*)&(hdr->DescList);
        printf("testing subcode %d   and   %d   \n",DescListLen,DescListPtr);
        int status = (FIPFunc[(Uint32) hdr->Code-1] [(Uint32) hdr->Subcode-1])(DescListPtr, DescListLen);
        return hdr;
    }
    unsigned char buffer[1500];
    
    int main( void )
    {
    	FIPfrm_t* FIPptr = malloc(sizeof(*FIPptr));
      	FIPptr = (struct FIPfrm_t *)(&buffer);
    	FIPptr->Hdr = (struct FIP_Hdr *)(&buffer[14]);
    	FIPptr->Hdr->Code = 1;
    	FIPptr->Hdr->Subcode =1;
    	FIPptr->Hdr = FIPHdrProcessing(FIPptr->Hdr);
        return 0;
    }
    I keep getting seg faults when i call on array of function pointers im not really sure whats going on here it should work.

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    NVM i found my problem how do u delete threads

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by kiros88 View Post
    NVM i found my problem how do u delete threads
    You don't.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. Passing my array to function
    By pooty tang in forum C Programming
    Replies: 8
    Last Post: 09-15-2004, 12:19 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM