(pattern *) pat & pattern * pat

This is a discussion on (pattern *) pat & pattern * pat within the C Programming forums, part of the General Programming Boards category; what is the difference between 1 & 2? 1. pat = (PATTERN *) vector(1,(int)*num_patfiles,sizeof(PATTERN)); 2. pat = PATTERN * vector(1,(int)*num_patfiles,sizeof(PATTERN));...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    22

    (pattern *) pat & pattern * pat

    what is the difference between 1 & 2?

    1. pat = (PATTERN *)
    vector(1,(int)*num_patfiles,sizeof(PATTERN));

    2. pat = PATTERN * vector(1,(int)*num_patfiles,sizeof(PATTERN));

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    look at it this way

    vector(1,(int)*num_patfiles,sizeof(PATTERN));

    this returns something. My guess is a pointer of some sort.

    (PATTERN *)

    this is a cast.So putting the 2 together you are casting the result of vector(blahblah) to a PATTERN* or a pointer to a PATTERN and storing that in the variable pat.

    pat = PATTERN * vector(1,(int)*num_patfiles,sizeof(PATTERN));

    This on the other hand is a multiplication. It shouldn't compile as pointers cant be multiplied. This says multiply PATTERN with the result of vector(blahblah) and store the result in pat.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visitor / Decorator Pattern
    By MarkZWEERS in forum C++ Programming
    Replies: 9
    Last Post: 05-16-2009, 11:53 AM
  2. Hmm.. Ai? Finding the pattern in number squences?
    By Zeusbwr in forum C++ Programming
    Replies: 8
    Last Post: 04-02-2005, 05:13 PM
  3. Abstract Factory pattern
    By Just in forum C++ Programming
    Replies: 3
    Last Post: 02-18-2005, 09:58 AM
  4. string pattern search problem
    By goron350 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 07:50 AM
  5. text pattern recognition
    By mtsmox in forum C++ Programming
    Replies: 5
    Last Post: 02-27-2002, 07:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21