LinuxQuestions.org
Review your favorite Linux distribution.
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 03-27-2012, 10:15 AM   #1
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Rep: Reputation: 2
_u32 _s32 defining in C, usning in structure.


1- is there a map or some thing which tell us how to define

_u32
_s32

in C language.

like is _u32 = int or is it long ?

2- If we use a pointer to structure. In that pointer do we need to dafine all the fields we are expecting back ? or pointer is enough and when we need to use those values then we need to handle them.

Thanks
 
Old 03-27-2012, 11:04 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
There are common definitions for various types in stdint.h.

For example, for _u32, you could use uint32_t, and for _s32, you could use int32_t.

As for your second question, I'm not sure exactly what you are asking, but if I understand you correctly, all you need to do is reference the structure via the pointer. If any structure members are not initialized, then I would tread carefully before relying on a particular value.

To demonstrate an example:
Code:
#include <stdint.h>
#include <stdio.h>

struct Foo
{
    uint32_t val1;
    int32_t  val2;
};

void initFoo(struct Foo* foo)
{
    if (foo != NULL)
    {
        foo->val1 = 10;
    }
}

int main()
{
    struct Foo myFoo;

    initFoo(&myFoo);

    printf("myFoo.val1 = %u\n", myFoo.val1);    /* will print 10 */

    printf("myFoo.val2 = %d\n", myFoo.val2);    /* will print "random" junk value */

    return 0;
}

Last edited by dwhitney67; 03-27-2012 at 11:05 AM.
 
Old 03-27-2012, 11:11 AM   #3
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
http://www.linuxjournal.com/article/5783

A pointer is only an address in memory so a structure must be defined first if you want to be able to reference it with a pointer.
 
Old 03-27-2012, 11:13 AM   #4
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
Oops, didn't see there was already an answer
 
  


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
Convert directory structure from long file names in Linux to DOS 8.3 structure? manorina Linux - Software 5 09-12-2009 09:18 AM
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 06:46 PM
defining servername as comps IP sherm Linux - Software 2 08-21-2004 05:32 PM
Defining terms Kurt M. Weber General 1 10-25-2003 07:25 PM
Defining the Slices desbyleo Solaris / OpenSolaris 10 05-07-2003 09:18 AM

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

All times are GMT -5. The time now is 04:17 PM.

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