Thread: are these functions possible in C?

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    are these functions possible in C?

    Code:
    void a(void) {
    	char x[1];
    	char y[1];
    	x = y;
    }
    
    
    
    
    void a(void) {
    	int x[1];
    	int y[1];
    	x = y;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    No.
    .
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so we can't assign an array to anything even, doing x = 5; or x = 'a'; will give an error? we can only assign if we index them?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Yup.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so doing x[5] = 'a'; is valid but x = y is not?

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    He already answered that... seriously think before you ask

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    and if I have :

    Code:
    int x;
    int y[5];
    x = y[2];
    this is valid

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    You aren't serious are you? Get a book. There are unlimited "is this valid" questions that could be asked, that's not the way to learn.

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    290
    What about this?
    Code:
    struct S {
       int A[1];
    };
    
    struct S s1 = {1};
    struct S s2 = s1;
    What about THIS?
    Code:
    struct S {
       int A[1];
       float B[1];
    };
    
    struct S s1 = {1, 2.0f};
    struct S s2 = s1;
    WHAT ABOUT THIS!!??
    Code:
    struct S {
       union {
          struct {
             int A[1];
          };
          struct {
             float B[1];
          };
       };
    };
    
    struct S s1 = {1};
    struct S s2 = s1;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM