Results 1 to 7 of 7

Thread: Difference between Macros and typedef

  1. #1
    Join Date
    Dec 2009
    Posts
    37

    Difference between Macros and typedef

    Hi friend,

    I am Bsc(IT) student . I have one question to ask you . I want to know the basci difference between the Macros and typedef. I don't have the sound knowledge regarding this Macros and typedef. Please let know some difference among Macros and typedef if you posses. I would greately appreciate your any help over this.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Difference between Macros and typedef

    typedef:
    'typedef' is basically useful to create a new name to the data type which is already exist. This redefinition of name normally creates conflict over the previously declared data type. The declaration of the 'typedef' doesn't create any new data type. It basically adds name to the existing data type. The newly renamed type has the same properties.
    Example:
    typedef unsigned float UINT32

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Difference between Macros and typedef

    Hi friend,

    Macros is nothing but a direct substitution of text before compilation of it's entire code. Macros are controlled by 'preprocessor'. Macro is 'directive' of the preprocessor it means the macros are being replace before it's compilation. See the following example of textual substitution. In which there where there is a possibility for redefining macro.
    Example:
    #define chPointer1 char *
    #undef chPointer1
    #define chPointer1 int *

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Difference between Macros and typedef

    * Macros are only do the replacements through the preprocessor while the typedef do the correct encoding of the pointers types.

    * typedef allows arrays declaration while Macros [#define] doesn't allow the arrays declaration.

    * typedef doesn't in fact create a new type while the Macros [#define] create new type.

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Difference between Macros and typedef

    Hi,

    I have one example of the 'typedef' declaration and it's use. I suggest you refer below example, it will definitely help you :
    include <stdio.h>
    typedef struct mystructtag1 {
    int i1;
    double f1;
    } mystruct1;

    int main() {
    mystruct ms1;
    ms1.i1 = 10;
    ms1.f1 = 0.99;
    printf("%d %f\n", ms1.i1, ms1.f1);
    }

  6. #6
    softtrickseo Guest

    Re: Difference between Macros and typedef

    Typedef is used to create a new name to an already existing data type. Redefine the name creates conflict with the previous declaration.

    eg:
    typedef unsigned int UINT32

    Macros [#define] is a direct substitution of the text before compling the whole code. In the given example its just a textual substitution. where there is a posibility of redifining the macro

    eg:
    #define chPointer char *
    #undef chPointer
    #define chPointer int *

  7. #7
    Join Date
    May 2008
    Posts
    2,012

    Re: Difference between Macros and typedef

    Hello friend,

    'Typedef' declarations used to construct shorter as well as meaningful names to the types which is already existed. Typedef allow us for encapsulating the implementation details which might change. The declaration of the 'typedef' doesn't declare new types instead it declares new names to the existing types. The limitation of 'typedef' is that you can not specify it in the definition of function. It share the name space along with ordinary identifiers.

Similar Threads

  1. What is the use of macros in the word?
    By bharti_rajpal in forum Windows Software
    Replies: 3
    Last Post: 07-12-2009, 01:41 PM
  2. Syntax: typedef typename F:: template
    By RyanInt in forum Software Development
    Replies: 3
    Last Post: 26-10-2009, 05:29 PM
  3. How to Run Excel Macros from ASP
    By Chain-SmokeR in forum Software Development
    Replies: 2
    Last Post: 04-07-2009, 12:23 PM
  4. Macros in Word
    By DanB in forum Windows Software
    Replies: 1
    Last Post: 02-06-2009, 08:09 AM
  5. What is MACROS in programming?
    By Claudius in forum Software Development
    Replies: 3
    Last Post: 06-03-2009, 12:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,997,750.68652 seconds with 17 queries