Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have strange erorr in this programme wich i got it is because of the follwing filebut i can not get any mistake in the following code:

C++
#include<iostream>
#include<string>
#include <stdlib.h>
#include"C:\users\shawki\desktop\sdright\clru.h"
#include "C:\users\shawki\desktop\sdright\IndexSpace.h"
#include"C:\users\shawki\desktop\sdright\stdafx.h"
#include"C:\users\shawki\desktop\sdright\CDPSpace.h"
#include"C:\users\shawki\desktop\sdright\Resource.h"
#include"C:\users\shawki\desktop\sdright\sd.h"

using namespace std;

#define COUNTER_BITS  (8)
typedef unsigned int (*hashfunc_t)(const char *);

 struct BLOOM {
    size_t asize;//size of bloom filter
    DWORD *a;//unsigned char *a;//pointer to the key value
    DATA_INDEX* PDATAINDEX[MAX_CACHE_DATA_INDEX_NUM];
    size_t nfuncs;//number of hash function
    hashfunc_t *funcs;//pointer for specific hash function
};



BLOOM *bloom_create(size_t size, size_t nfuncs, ...);//bloom filter constructor.
int bloom_destroy(BLOOM *bloom);//bloom filter destructor.
int bloom_increament(BLOOM *bloom, DWORD *s);//add new element to bloom filter function.
int bloom_decrement(BLOOM *bloom,DWORD *s);//delete new elements from bloom filter function.
int bloom_check(BLOOM *bloom, DWORD *s);//check the existence of value in bloom filter.

#endif


where the errore is :
C++
1>------ Build started: Project: sd, Configuration: Release Win32 ------
1>  stdafx.cpp
1>C:\users\shawki\desktop\sdright\clru.h(18): error C2143: syntax error : missing ';' before '*'
1>C:\users\shawki\desktop\sdright\clru.h(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\users\shawki\desktop\sdright\clru.h(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


so please help me to know the reason of this error
Posted
v2
Comments
Philippe Mori 4-Aug-11 20:57pm    
I think you don't even have post the code from C:\users\shawki\desktop\sdright\clru.h as I see an #include for that file at line #4.

DWORD is a windows type you must include windows.h or use unsigned long instead.
Regards.
 
Share this answer
 
Comments
hakz.code 4-Aug-11 5:23am    
My 5 that should solve the problem,if the project is built with pre compiled headers then #include "stdafx.h" will do
CPallini 4-Aug-11 6:54am    
[On behalf of the (bit rude) OP]: I HAVE DONE THAT BEFORE THE SAME THING IS STILL COME OVER AND OVER.
hakz.code 4-Aug-11 8:08am    
if this was the win32 project with precompiled header #include "stdafx.h" would include the stdafx.h of current project which contains the following:

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>

// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>


// TODO: reference additional headers your program requires here




and the #include"C:\users\shawki\desktop\sdright\stdafx.h" present in the post would not have that because if it had then this issue wouldn't have come up.
sigh
:)
but thanks for the comment,this really makes me think over
hi thank you i have solved the problem really it was so simple just add (struct) before BLOOM that was really too simple thank you for your cooperating.but i just want to ask you other question how can i make this BLOOM 4 bit counter it is 8 bit counter as it is shown in the first file i had posted where is the source code for it is bloom_filter.ccp is as follow:

C#
#include<limits.h>
#include<stdarg.h>
#include<math.h>
#include<string.h>
#include"bloom_filter.h"
#include"clru.h"
#include"uthash.h"
#include"stdafx.h"
#include"CDPSpace.h"
#include"Resource.h"
#include"sd.h"
#include"./lib/md5.h"
  CBloom_Filter::CBloom_Filter(){
BLOOM *bloom=CBloom_Filter::bloom_create((size_t)ceil(0.5*1*1.44), 1,MD5String);
  }
  CBloom_Filter::~CBloom_Filter(){


  }

 BLOOM *CBloom_Filter::bloom_create(size_t size, size_t nfuncs, ...)//bloom filter constructor.
{
    BLOOM *bloom;
    va_list l;//variable refer to the expected parameter (…)
    int n;

    if(!(bloom = (BLOOM *)malloc( sizeof(BLOOM)))) return NULL;//to allocate memory for bloom filter when is there is no bloom filter return null.
    if(!(bloom->a=(unsigned char *)calloc((size*COUNTER_BITS+CHAR_BIT-1)/(CHAR_BIT), sizeof(char)))) {
        free(bloom);
        return NULL;
    }//to allocate array of memory a(which represents pointer for key value) when it is fail just free the bloom filter and return null.

    if(!(bloom->funcs=(hashfunc_t*)malloc(nfuncs*sizeof(hashfunc_t)))) {
        free(bloom->a);
        free(bloom);
        return NULL;

C#
}//to allocate memory for pointer to specific hash function when it fails it free memory reserved by a(pointer to key) and bloom filter and return null.


    va_start(l, nfuncs);//this macro we use it in order to  initializes (l) variable for subsequent use by va_arg and va_end, and must be called first.
//The parameter (nfuncs) is  the  name  of  the  last  parameter before  the variable argument list, i.e., the last parameter of which the calling function knows the type.
//Because the address of  this  parameter  is  used  in  the va_start  macro,  it  should not be declared as a register variable, or as a function or an array type. The va_start macro returns no value.


    for(n=0; n<nfuncs; ++n) {
        bloom->funcs[n]=va_arg(l, hashfunc_t);// The va_arg macro expands to an  expression  that  has  the type  and  value  of  the  next argument in the call.  The parameter(l)  is the va_list l  initialized  by  va_start.
//Each  call  to  va_arg  modifies (l) so that the next call returns the next argument.  The parameter type is  a  type
//name  specified so that the type of a pointer to an object that has the specified type  can  be  obtained  simply  by adding a * to type. If there is no next argument, or if type is not compatible with the type of the actual  next  argument  (as promoted
//according  to  the  default  argument  promotions), random errors will occur.
//The first use of  the  va_arg  macro  after  that  of  the va_start  macro  returns the argument after last.  Successive invocations return the values of the remaining arguments.

    }
    va_end(l);// The va_end macro handles a normal return from the function whose variable argument list was initialized by  va_start.

    if (!(bloom->PDATAINDEX[0]=(DATA_INDEX*)malloc((MAX_DATA_INDEX_NUM)*sizeof(DATA_INDEX)))){
        free(bloom->PDATAINDEX);
        free(bloom->a);
        free(bloom);
        return NULL ;
    }
    bloom->nfuncs=nfuncs;
    bloom->asize=size;
    const char *s=(const char*)bloom->a;


    memset(bloom->a,0,(size*COUNTER_BITS+CHAR_BIT-1)/(CHAR_BIT));


    return bloom;
}

int CBloom_Filter:: bloom_destroy(BLOOM *bloom)
{
    free((void*)bloom->asize);
    free(bloom->a);
    free(bloom->PDATAINDEX);
    free((void*)bloom->nfuncs);
    free(bloom->funcs);
    free(bloom);

    return 0;
}

int CBloom_Filter:: bloom_increament(BLOOM *bloom, const char *s)//where (s)is pointer for the key value
{
    size_t n;

    for(n=0; n<bloom->nfuncs; ++n) {

    if  (bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]<225)
        bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]++;

    }

    return 0;
}
int CBloom_Filter:: bloom_decrement(BLOOM *bloom,const char *s)
{
    size_t n;

    for(n=0;n<bloom->nfuncs;++n){
        if (bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]>0)
        bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]--;


    }
    return 0;
}
int CBloom_Filter::  bloom_check(BLOOM *bloom, const char *s)
{
    size_t n;

    for(n=0; n<bloom->nfuncs; ++n) {
        if(bloom->a[((*(bloom->funcs[n]))(s))%(bloom->asize)]>=1)

        return true;//here we substitute with key value in each hash function checking each corresponding counter which is equal to 1 or not
        else
        return false;
    }


}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900