473,698 Members | 2,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C compile time error

6 New Member
I'm using gcc to compile the code listed below when I get the following error

error: expected '=', ',', ';', 'asm' or '__attribute__' before ' is_prime_number

Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * What is the largest prime factor of the number 317584931803?
  3.  */
  4.  
  5. #include <stdio.h>  
  6. #include <stdlib.h>  
  7.  
  8. bool is_prime_number(unsigned long number){
  9.     if(number < 2){
  10.         return false;
  11.     }
  12.  
  13.     bool is_a_prime = true;
  14.     unsigned long i;
  15.     unsigned long factor = number/2;
  16.  
  17.     for(i=factor;i>1;i--){
  18.         if(number%i == 0){
  19.            is_a_prime = false; 
  20.            break;
  21.         }
  22.     }
  23.  
  24.     return is_a_prime;
  25. }
  26.  
  27. int main(int argc, char* argv[]){
  28.     if(argc != 2){
  29.         fprintf(stderr, "Usage: ./euler_3 <number>\n");
  30.         exit(1);
  31.     }
  32.  
  33.     unsigned long max_val, biggest, result, i; 
  34.     max_val = strtoul(argv[1], NULL, 10);
  35.     biggest = max_val/2;
  36.  
  37.     //check in the reverse direction if the number is a factor of max_val
  38.     for(i=biggest; i>1; i--){
  39.         if(max_val%i == 0){
  40.             //check if the number is a prime number
  41.             if(is_prime_number(i)){
  42.                 result = i;
  43.                 break; 
  44.             }
  45.         } 
  46.     }
  47.  
  48.     printf("Largest prime factor: %d", result);
  49.     exit(0);
  50. }
  51.  
Any pointers will be greatly appreciated. Thanks in advance.
Jan 4 '08 #1
2 1652
entellus
6 New Member
I'm using gcc to compile the code listed below when I get the following error

error: expected '=', ',', ';', 'asm' or '__attribute__' before ' is_prime_number
compiling with g++ -o file file.c works just fine. strange!

thanks
Jan 4 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Not strange at all.

bool does not exist in C.
Jan 5 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3328
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new rightType;
5
3813
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace ) Person.xsd includes Common-Naming.xsd ( anonimous schemas ) Common-Naming.xsd includes common.xsd ( both are anonimous schemas ) Compilation of Resident.xsd raise the following exception: "System.Xml.Schema.XmlSchemaException: The attribute 'oid'...
2
4626
by: Glen | last post by:
I'm working on a custom assembly and I'm trying to figure out the best approach to handling known constraints within the assembly, once compiled, to alert the developer at compile time of a potential issue. For example, in the assembly I would like to add a constraint that states a particular property member of the class can not be equal to one other property. In standard coding I can throw an exception during run-time, but I would rather...
13
3059
by: Adam Blair | last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time error is raised if not all values within the Enum are handled in the switch statement? I realise you can use default: to catch unhandled cases, but of course this is only at run-time. Example: public enum MyEnum { one, two, three, four }
0
2509
by: ufnuceda | last post by:
Hello everyone, I was wondering if any of you have some experience with the boost library. I am having trouble compiling code with it. Since boost is being used a lot these days I thought some of you might have an answer. I would greatly appreciate help with this, as I tried to search for an answer for quite some time in vain. I am getting error messages when I try to compile as soon as I put an include to the boost library in the...
14
2576
by: Urs Thuermann | last post by:
What is the most elegant way to check certain conditions at compile time? I.e. I want a compile time error to be generated if for example the size of a struct is not a multiple of 4 or if one struct is larger than another struct, etc. I think of something like #define CHECK(expr) static int dummy CHECK(sizeof(struct foo) % 4 == 0);
1
5390
by: electrixnow | last post by:
Help!, I need to compile this code with static libs so it run on another XP machine that does'nt have MS Studio installed. When I compile now I get an ERROR: 1>------ Rebuild All started: Project: drawing_control, Configuration: Release Win32 ------ 1>Deleting intermediate and output files for project 'drawing_control', configuration 'Release|Win32'
15
4829
by: steve yee | last post by:
i want to detect if the compile is 32 bits or 64 bits in the source code itself. so different code are compiled respectively. how to do this?
9
3510
by: ThunderMusic | last post by:
Hi, I'd like to create a compile time error in my class... maybe there's a way already built in in the framework so I can achieve what I want... I have 2 constructors in my class. One of them has mandatory parameters, I mean, they should not be null nor empty (for strings). So I'd make the validation in the constructor and generate a compile-time error if the validation does not match... Is there a way to achieve this or to specify...
12
2756
by: Ioannis Vranos | last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard, something simple like defining a function as: void somefunc(void) throw() { // ... }
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.