[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C programming question



On Thu, 15 Apr 2010 17:39:42 -0400 (EDT), Boyd Stephen Smith Jr. wrote:
> Stephen Powell wrote:
>> In short, I need to
>> (a) declare "cms_label" as a based structure,
>
> (above; trimmmed)
>>
>> (b)
>> declare a pointer variable called  "cms_ptr" and associate it with the
>> "cms_label" structure,
> 
> struct cms_label *cms_ptr;
>
> Initialization optional, but recommended.
>>
>> (c)
>> make sure that the compiler does not attempt
>> to allocate any storage for the "cms_label" structure,
> 
> Since you are declaring a pointer to a structure, and not declaring an object 
> with type "struct cms_label", no space will be allocated for a cms_label.
>>
>> (d)
>> make sure that the compiler automatically acquires storage for the
>> "cms_ptr" pointer variable itself,
> 
> Make your declaration a definition and that'll be handled.  (Declarations and 
> definitions look very similar for non-function types; the code given above is 
> actually a definition if it is not within a struct/union type.)
>>
>> (e)
>> assign the address of the "volume_label" structure
>> to the "cms_ptr" pointer variable at an appropriate point in the code,
>> and
> 
> struct volume_label vl;
> struct cms_label *cms_ptr;
> 
> /* Load data into vl */
> /* Determine that the data is actually a cms_label */
> cms_ptr = (void *) &vl;
> 
> Or, in your specific case, you should be able to do something like:
> 
> struct cms_label *cms_ptr = (void *) disk_specific->anchor->vlabel;
>
> Since you are already dealing with a "struct volume_label *", there's no need 
> for the address-of operator (&).
>>
>> (f)
>> make references to the members of the cms_label structure.
> 
> cms_ptr->label_id; /* Or any other member. */
>>
>> How do I do this?  (Man, I wish I knew C!)
> 
> Examples above good?  Please let me know if I can provide further assistance.

Yahoo!  It works!  Thanks a bunch, Boyd.

I'm going to be filing a bug report against parted for (a) miscalculating the starting
block of the implicit partition on an ldl (Linux Disk Layout) formatted disk on the
s390 architecture when the block size is other than 4096, and (b) no support for
CMS-formatted disks.  I'm going to include my patch files for the fix in the bug
report.  Would you like to be in the credits?  Or would you prefer to remain anonymous?

-- 
  .''`.     Stephen Powell    
 : :'  :
 `. `'`
   `-


Reply to: