LinuxQuestions.org
Visit Jeremy's Blog.
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 04-19-2012, 01:50 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
Primitive questions


Dear all,
I am having few questions regarding c (I am starting a new thread) as I do not want to mix those with me previous network programming questios, I posted here earlier.



1) I found that one can get information about basic c function from linux bash with man... Well I have to admit that I did not expect that. I thought that the man is only related to the bash linux only. Where it gets the information for the the c libraries. How it distingushes between c and bash commands?

2) I have found in my c document a text about macros. What is a macro? Is for example the sizeof myvariable a macro? Where these are declared?

3) IF i have a struct lets call it mystruct and then I do memset(&mystruct,0, sizeof mystruct) this will set to zeros all the variables inside of the struct, regardless what type of variables it includes. Is not that right?

I would like ot thank you in advance for your help
Regards
Alex
 
Old 04-19-2012, 02:20 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
1. man has sections. see man man. In general you can ask for a manual of anything available on a linux.
2. macro: http://h30097.www3.hp.com/docs/base_...E/DOCU_077.HTM
3. right
 
Old 04-19-2012, 03:34 AM   #3
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by pan64 View Post
1. man has sections. see man man. In general you can ask for a manual of anything available on a linux.
2. macro: http://h30097.www3.hp.com/docs/base_...E/DOCU_077.HTM
3. right
3) and what is the difference between define and typedef? Could not be only that define does also the work of typedef?
 
Old 04-19-2012, 03:38 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
define is general, you can do strange things with define, for example:
Code:
#define BUBBLE +
int a, b, c;
a=5;
b=7;
c = a BUBBLE b;  # this will work, c will be 12
typedef is only used to declare new types, or give unique names to given types.
with this you can force the compiler for stricter checks
 
1 members found this post helpful.
Old 04-19-2012, 04:43 AM   #5
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by pan64 View Post
define is general, you can do strange things with define, for example:
Code:
#define BUBBLE +
int a, b, c;
a=5;
b=7;
c = a BUBBLE b;  # this will work, c will be 12
typedef is only used to declare new types, or give unique names to given types.
with this you can force the compiler for stricter checks
I need a clarification here, can I also do
#define int mytype # (the second # ends the define statement)
and then use mytype to define a new data type

mytype MyNewIntegerVariable

What is the "extra" that typedef offers?
Alex
 
Old 04-19-2012, 04:53 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
in case of a macro the preprocessor will evaluate it and therefore they will replace mytype with int, so the syntax checker will see int.
in case of typedef the preprocessor will leave it as is (because it is not a macro) and the syntax checker will be able to handle them as different types.
so in case of macro (#define int mytype) void myfunc(int) and void myfunc(mytype) will be exactly the same, using typedef they will be incompatible, so you can distinguish them.
the compiler will generate the same code anyway.
 
Old 04-20-2012, 11:30 AM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by alaios View Post
3) and what is the difference between define and typedef? Could not be only that define does also the work of typedef?
Here's an illustrative example:
Code:
typedef int size_type;

#define MAIN_START int main() {
#define MAIN_STOP  }

MAIN_START
    size_type some_value = 0;
    return some_value;
MAIN_STOP
A macro can be used to define arbitrary text replacements, whereas a typedef has semantic meaning in C.
Kevin Barry

Last edited by ta0kira; 04-20-2012 at 09:25 PM.
 
1 members found this post helpful.
  


Reply


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
Java: Quick question about primitive data type long. vxc69 Programming 3 06-27-2008 04:46 PM
Error while compiling kernel 2.6.25 with IPP(Intel Integrated Performance Primitive) sathishkumarp Linux - Kernel 2 05-28-2008 11:35 PM
FC6 boots into VERY primitive and corrupt -looking X this morning. Jyde Linux - General 8 06-19-2007 08:10 AM
Primitive root implementation zWaR Programming 3 03-26-2007 06:12 PM
Login screen looks primitive. no KDM? TSloth Mandriva 8 01-06-2006 07:09 PM

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

All times are GMT -5. The time now is 09:37 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