Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simple question about void functions

Status
Not open for further replies.

highlander11

Junior Member level 3
Joined
Jun 19, 2010
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,523
lets say you have two exzact functions:

void happy(void)
{
.....
}

and


void happy()
{

}

whats the difference ?

I understnad that void at the satart mean that a value will not be returned to the main function and a void in the () means?

note : does it mean that it wont get a value into the function?



thanks for any answer highlander11
 

Re: simple void question

Both define a function returning void, and accepting zero arguments.

They define `func' with different types. The first type is a type with a prototype, the second type is without a prototype.
If in a function call expression the expression designating the function has a type without a prototype, and any arguments
are passed, compiler is not required to diagnose an error, but the behaviour is undefined.

void f();
f(x); //UB, no diagnostic

void f(void);
f(x); //diagnostic

This is only undefined behaviour when the actual function f has not a single parameter. "void f();" declares a function f that returns void with an unspecified number of parameters of unspecified type. So f(x) is undefined behaviour if the actual function does *not* have a single parameter.
 

Re: simple void question

sorry for saying this but I didnot understand your answer

could you give an example with numbers or just an a=נ finction stuff

since I tested both functions in real 89c5131 hardware and there is no difference



sorry for the inconvenience :)
 

Re: simple void question

Both define a function returning void, and accepting zero arguments.

They define `func' with different types. The first type is a type with a prototype, the second type is without a prototype.
If in a function call expression the expression designating the function has a type without a prototype, and any arguments
are passed, compiler is not required to diagnose an error, but the behaviour is undefined.

void f();
f(x); //UB, no diagnostic

void f(void);
f(x); //diagnostic

This is only undefined behaviour when the actual function f has not a single parameter. "void f();" declares a function f that returns void with an unspecified number of parameters of unspecified type. So f(x) is undefined behaviour if the actual function does *not* have a single parameter.


Yahh u r right.
 

lets say you have two exzact functions:

void happy(void)
{
.....
}

and


void happy()
{

}

whats the difference ?

I understnad that void at the satart mean that a value will not be returned to the main function and a void in the () means?

note : does it mean that it wont get a value into the function?



thanks for any answer highlander11

The void within the bracket means that the function will not accept any value, ie, it acts like a procedure - no value is passed to the function and no value is returned, meaning that the function just carries out a task without accepting/returning any values.

If you don't write void, the compiler takes that you mean void. eg.
Code:
void happy(void)
Code:
void happy()
mean the same thing.
In the 2nd statement, when nothing is specified within the brackets, the compiler takes that as "void", but there's no harm in writing "void".

Hope this helps.
Tahmid.
 

1st function does not return any value nor takes any arguements............ the second can take arguements but will not return any value

Well in second case it dosen't take argument. as the generated code for both the case are same. Only difference is while calling the functions.

if categorically void is mentioned as parameter to function( first case) the compiler will generate an error message during compilation, if some value is passed. In the other case it wont.
 
  • Like
Reactions: blooz

    blooz

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top