Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-29-2008, 01:50 AM   #1
LQ Newbie
Registered: Jul 2008
Posts: 15

Rep: Reputation: 0
Structure in C

Hi Everyone....
I have a structure:
typedef struct
unsigned char command;
unsigned char data_length;
char data[MAX_DATA_LENGTH];

My problem is that,I want to use a function here...
When i assign values to these variables they are as:
I want to call a function here..or assign a function value here........

is it possible to do so...

Thanks ...
Old 09-29-2008, 02:46 AM   #2
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
Yes it's possible, you have to use a pointer on function, something like

struct Packet {
    int (*do_command) (arg);
    unsigned char data_length;
    char data [MAX_DATA_LENGTH];

int my_command (arg) {
   /* Do what you want */

int main (void) {
   struct Packet packet;
   packet.do_command = my_command;
   /* ... */


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 06:46 PM
structure browser? jiml8 Programming 16 05-18-2008 04:48 PM
structure within a structure in C knobby67 Programming 3 03-06-2007 09:00 AM
structure os2 Programming 6 05-29-2005 07:39 PM
Forum Structure Lord-Rashid LQ Suggestions & Feedback 9 05-15-2004 10:31 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:01 PM.

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