Re: forloop doesn't take define?
- From: "Bill Davy" <Bill@xxxxxxxxxxxxxx>
- Date: Thu, 30 Oct 2008 07:39:49 -0000
"Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D31E6B50-8298-40F1-8EC0-6BF72CDB6999@xxxxxxxxxxxxxxxx
oaoaoaoh!
me double stupid!
Thankyou for your help fellows !
--
Best regards
Roberto
"Igor Tandetnik" wrote:
Robby <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
c:\_DTS_PROGRAMMING\C_PROGRAMMING\c\ARRAYSIZES\test.cpp(29): error
C2296: '/' : illegal, left operand has type 'long [5]'
#define SX (sizeof((obj_M->pCOLL[0].SFI) /
(sizeof(obj_M->pCOLL[0].SFI[0]))))
I'm pretty sure you wanted to arrange the parentheses differently. For
clarity, let's replace obj_M->pCOLL[0].SFI with A (for "array"):
#define SX (sizeof( (A) / (sizeof(A[0])) ))
So you try to do "A/sizeof(A[0])", and then apply sizeof to the result.
But of course A/sizeof(A[0]) is nonsense. You likely meant
#define SX ( sizeof(A) / sizeof(A[0]) )
See the difference?
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
This dialogue is a perfect example of how newsgroups should function, so
hats off to you both.
I would just add that as your example has demonstrated, macros and complex
things get muddled (in a Pooh sense), the following in a header file saves
my bacon (or honey) time and again.
//
// A means of finding the size of a fixed array which also has the nice
// property that it fails if passed a pointer, unlike
(sizeof(pointer)/(pointer[0])).
//
//
http://groups-beta.google.com/group/microsoft.public.vc.ide_general/msg/cb86476c29a61072?dmode=source
//
template <typename Type, ::size_t nElements> inline
::size_t sizeof_array(const Type (&)[nElements])
{
return nElements;
}
.
- Follow-Ups:
- Re: forloop doesn't take define?
- From: sasha
- Re: forloop doesn't take define?
- References:
- forloop doesn't take define?
- From: Robby
- Re: forloop doesn't take define?
- From: Igor Tandetnik
- Re: forloop doesn't take define?
- From: Robby
- forloop doesn't take define?
- Prev by Date: VC++: Trying to change taskbar icons using notifyIcon1 and imageList1
- Next by Date: Re: .sys format?
- Previous by thread: Re: forloop doesn't take define?
- Next by thread: Re: forloop doesn't take define?
- Index(es):
Relevant Pages
|