Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 27th, 2009, 9:16 PM   #1
magnus
Programmer
 
Join Date: Sep 2008
Posts: 95
Rep Power: 6 magnus is on a distinguished road
"Too few arguments to function...", but there seems to be enough...

A little practice project, the purpose is to obtain states of individual bits of an integer value. Now, I'm having a little problem, and I just can't figure it out...
namespace bin {
	const int INTSIZE = sizeof(int) * 8;
	bool get_bit(int value, int bit, bool big_endian);
	void parse_bits(int value, bool bits[]);
	void endianswap(bool bits[], int number_of_bits);
}

using namespace bin;

bool bin::get_bit(int value, int bit, bool big_endian = false) {
	static int previous_value;
	static bool previous_endianness_big;
	static bool bits[INTSIZE];
	if(value != previous_value || previous_endianness_big != big_endian ) {
		previous_value = value;
		previous_endianness_big = big_endian;
		parse_bits(value, bits);
		if(big_endian) endianswap(bits);
	}
	return bits[bit];
}

void bin::parse_bits(int value, bool bits[]) {
	while(value) {
		if(value & 1) *bits = true; else *bits = false;
		bits++;
		value = value >> 1;
	}
}

void bin::endianswap(bool bits[], int number_of_bits = INTSIZE) {
	for(int i = 0; i <= number_of_bits / 2; i++) {
		bool tmp = bits[i];
		bits[i] = bits[number_of_bits - i];
		bits[number_of_bits - i] = tmp;
	}
}
The bolded line comes up with the error message "too few arguments to function ‘void bin::endianswap(bool*, int)". I have a feeling it's a simple stupid mistake I've made, but I just can't figure it out...
magnus is offline   Reply With Quote
Old Sep 27th, 2009, 9:45 PM   #2
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: "Too few arguments to function...", but there seems to be enough...

>>void bin::endianswap(bool bits[], int number_of_bits = INTSIZE) {

The default value for the second parameter goes in the function prototype, but not in the implementation code.
namespace bin {
	const int INTSIZE = sizeof(int) * 8;
	bool get_bit(int value, int bit, bool big_endian);
	void parse_bits(int value, bool bits[]);
	void endianswap(bool bits[], int number_of_bits  = INTSIZE);
}
void bin::endianswap(bool bits[], int number_of_bits) {
	for(int i = 0; i <= number_of_bits / 2; i++) {
		bool tmp = bits[i];
		bits[i] = bits[number_of_bits - i];
		bits[number_of_bits - i] = tmp;
	}
}
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline   Reply With Quote
Old Sep 27th, 2009, 9:46 PM   #3
The Dark
Programming Guru

 
Join Date: Jun 2005
Posts: 1,630
Rep Power: 12 The Dark will become famous soon enoughThe Dark will become famous soon enough
Re: "Too few arguments to function...", but there seems to be enough...

Are you sure it is that line with the error, not this one?
		if(big_endian) endianswap(bits);
You only have one parameter passed into the function where it is expecting two.

Edit: Too slow, and A.D.'s answer is better anyway.
The Dark is offline   Reply With Quote
Old Sep 27th, 2009, 9:59 PM   #4
magnus
Programmer
 
Join Date: Sep 2008
Posts: 95
Rep Power: 6 magnus is on a distinguished road
Re: "Too few arguments to function...", but there seems to be enough...

Well, that did it, but there's one thing I don't get... there's a default value for the get_bit function as well, which I put in the implementation, but it didn't give any errors...
magnus is offline   Reply With Quote
Old Sep 27th, 2009, 11:46 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 8,368
Rep Power: 19 DaWei will become famous soon enoughDaWei will become famous soon enough
Re: "Too few arguments to function...", but there seems to be enough...

You can supply an argument for a default value but you can't fail to supply an argument for a non-default value. Is that what you're asking?
__________________
Contributor's Corner:
Politically Incorrect
DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 28th, 2009, 3:18 AM   #6
magnus
Programmer
 
Join Date: Sep 2008
Posts: 95
Rep Power: 6 magnus is on a distinguished road
Re: "Too few arguments to function...", but there seems to be enough...

Quote:
You can supply an argument for a default value but you can't fail to supply an argument for a non-default value. Is that what you're asking?
No, it's about my code; I (erroneously) put the default argument (in endianswap function) in the implementation of the function, when it was supposed to be in the declaration, and when I changed this it did indeed compile without a hitch; however, as you can see, in the other function (get_bit) also has the default argument in the implementation, but that didn't raise any error messages or even warnings, and it compiled just fine.
magnus is offline   Reply With Quote
Old Sep 28th, 2009, 6:12 AM   #7
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: "Too few arguments to function...", but there seems to be enough...

did you try int number_of_bits = bin::INTSIZE bool is a standard c++ data type, but INTSIZE is not.
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline   Reply With Quote
Old Sep 28th, 2009, 3:38 PM   #8
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 331
Rep Power: 9 Cache is on a distinguished road
Re: "Too few arguments to function...", but there seems to be enough...

Quote:
Originally Posted by magnus View Post
No, it's about my code; I (erroneously) put the default argument (in endianswap function) in the implementation of the function, when it was supposed to be in the declaration, and when I changed this it did indeed compile without a hitch; however, as you can see, in the other function (get_bit) also has the default argument in the implementation, but that didn't raise any error messages or even warnings, and it compiled just fine.
There is nothing wrong with placing the default value in the implementation (definition). The problem comes when any calling code cannot see that default value but attempts to use it.

Consider following:

// endian.h
void f(int, int);

// endian.cpp
#include "endian.h"
void x1() { f(0, 0); }  // OK.
void x2() { f(0); }     // error: cannot see f(int, int = 0) here.
void f(int, int = 0) {}
void x3() { f(0, 0); }  // OK.
void x4() { f(0); }     // OK.

// user.cpp
#include "endian.h"
void x5() { f(0, 0); }  // OK.
void x6() { f(0); }     // error: cannot see f(int, int = 0) here.
Cache is offline   Reply With Quote
Old Sep 28th, 2009, 5:27 PM   #9
magnus
Programmer
 
Join Date: Sep 2008
Posts: 95
Rep Power: 6 magnus is on a distinguished road
Re: "Too few arguments to function...", but there seems to be enough...

Ohh okay, that cleared everything out for me thanks
magnus is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ - Creating programs that utilize command line arguments. lrh9 C and C++ 1 Mar 23rd, 2009 10:21 PM
Can't pass const arguments to function of template class sidlee C++ 7 Feb 16th, 2009 2:49 PM
Calling a function with an indeterminate number of arguments woozy PHP 7 Mar 15th, 2007 2:34 AM
Too many arguments to function... layer C++ 12 Apr 30th, 2005 1:40 AM
Passing pointers as function arguments? (C) Duo C++ 6 Mar 15th, 2005 3:20 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:19 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC