473,388 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

problem understanding c code

hi

i'm going to develope an mp3 encoder and therefor i'm studiing the source
code of lame mp3 encoder. but i'm not able to anderstand the nixt three
lines of the sourde.

struct lame_global_struct;
typedef struct lame_global_struct lame_global_flags;
typedef lame_global_flags *lame_t;

maybe you can tell me how it works.

thank you
andi
Nov 14 '07 #1
4 1609
On Nov 14, 11:56 am, Andreas <a.kas...@kabsi.atwrote:
hi

i'm going to develope an mp3 encoder and therefor i'm studiing the source
code of lame mp3 encoder. but i'm not able to anderstand the nixt three
lines of the sourde.

struct lame_global_struct;
typedef struct lame_global_struct lame_global_flags;
typedef lame_global_flags *lame_t;
The 2nd line defines "lame_global_flags" to be a name
for the type "struct lame_global_struct" and the 3rd
line defines "lame_t" to be a name for the type "pointer
to lame_global_flags". In other words lame_t is a name
for the type "pointer to struct lame_global_struct".

Nov 14 '07 #2
and the fist line? what means it? - no structure of the datatype is
defined?

struct lame_global_struct;


Am Wed, 14 Nov 2007 12:03:54 +0000 schrieb Spiros Bousbouras:
On Nov 14, 11:56 am, Andreas <a.kas...@kabsi.atwrote:
>hi

i'm going to develope an mp3 encoder and therefor i'm studiing the
source code of lame mp3 encoder. but i'm not able to anderstand the
nixt three lines of the sourde.

struct lame_global_struct;
typedef struct lame_global_struct lame_global_flags; typedef
lame_global_flags *lame_t;

The 2nd line defines "lame_global_flags" to be a name for the type
"struct lame_global_struct" and the 3rd line defines "lame_t" to be a
name for the type "pointer to lame_global_flags". In other words lame_t
is a name for the type "pointer to struct lame_global_struct".
Nov 14 '07 #3
Spiros Bousbouras wrote:
On Nov 14, 11:56 am, Andreas <a.kas...@kabsi.atwrote:
>hi

i'm going to develope an mp3 encoder and therefor i'm studiing the source
code of lame mp3 encoder. but i'm not able to anderstand the nixt three
lines of the sourde.

struct lame_global_struct;
typedef struct lame_global_struct lame_global_flags;
typedef lame_global_flags *lame_t;

The 2nd line defines "lame_global_flags" to be a name
for the type "struct lame_global_struct" and the 3rd
line defines "lame_t" to be a name for the type "pointer
to lame_global_flags". In other words lame_t is a name
for the type "pointer to struct lame_global_struct".
Which the OP could have found out by opening his C reference text.

I suspect his question is really about the declaration of the "opaque"
structure...

This is a common technique in interface design, when a subsystem needs
to be passed a (pointer to a) structure but we don't want the users of
the subsystem to be aware of its composition.

I would expect users of lame to only really work with lame_t data -
pointers to structures, but we don't know (or care) what the structures
looks like.
Nov 14 '07 #4
Andreas <a.******@kabsi.atwrites:
Am Wed, 14 Nov 2007 12:03:54 +0000 schrieb Spiros Bousbouras:
>On Nov 14, 11:56 am, Andreas <a.kas...@kabsi.atwrote:
>>i'm going to develope an mp3 encoder and therefor i'm studiing the
source code of lame mp3 encoder. but i'm not able to anderstand the
nixt three lines of the sourde.

struct lame_global_struct;
typedef struct lame_global_struct lame_global_flags;
typedef lame_global_flags *lame_t;

The 2nd line defines "lame_global_flags" to be a name for the type
"struct lame_global_struct" and the 3rd line defines "lame_t" to be a
name for the type "pointer to lame_global_flags". In other words lame_t
is a name for the type "pointer to struct lame_global_struct".

and the fist line? what means it? - no structure of the datatype is
defined?
Please don't top post.
struct lame_global_struct;
It says that there is a struct called lame_global_struct and no more.
It is used when the programmer wants to talk about a structure without
saying anything more about it. In the example above, the programmer
wants to define a synonym for the structure type and for a pointer to
it. There is not much else you can do with it which is sometimes the
whole purpose (look up "opaque types").

There is no need to write it out like that.

typedef struct lame_global_struct lame_global_flags;
typedef lame_global_flags *lame_t;

serves the same purpose (in C). The original may have been written
because, to a C++ compiler, a structure tag is a legal type name and
the code may have once have had things like:

some_function(lame_global_struct *sp);

in it once, or simply the author may have adopted that style because
he/she is used to it from C++.

--
Ben.
Nov 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jole | last post by:
Hi I'm using serialization to read in an object from a file. My code basically does this: 1)MyClass obj = (MyClass) in.readObject(); ('in' is an ObjectInputStream wrapped around a...
4
by: Me | last post by:
I am not understanding an aspect of how to implement a class template in a ..cpp file. What I do know is that there are at least two problems with my understanding of how to accomplish the...
12
by: Torbjørn Pettersen | last post by:
I'm having problems validating my HTML code because of some ASP code I'm using: ---Start Code--- <% If rs("Average") = 0 Then VotingImage = "<img src="/images/0.gif" alt='No votes yet'>"...
4
by: Bangalore | last post by:
Hi all, I am finding quite difficulty in understanding the behaviour of the following program. Base class is singleton, so it should allow the creation of only one object. Eventhough it is...
17
by: Phil McKraken | last post by:
I am having a problem putting together a shopping cart with the below script. Everything displays fine, adds totals fine, and works perfect EXCEPT if you choose the 9.95 item #5 BY ITSELF the total...
37
by: Patrik Huber | last post by:
Hello! I got the following Code in Assembler (NASM), which prints out "5" in realmode: mov ax, 0xB800 mov es, ax mov byte , '5' I want to do the same in gcc now, but I'm stuck. GCC...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.