LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2007, 02:31 AM   #1
kskkumar
Member
 
Registered: Aug 2005
Posts: 40

Rep: Reputation: 15
disable a particular warning in C


I have my code and i get some warnings like

warning: initialization makes pointer from integer without a cast

which i knew it will happen. and this is a scenario some thing like shown below

typedef union
{
int *a;
int a1;
}MyUn;

when i try to initialize this union like

MyUn someVar = {1}

I get a warning

warning: initialization makes pointer from integer without a cast

I knew that 1 is not a pointer but integer. but it still show this warning. How to disable this warning / supress this warning message?
 
Old 10-18-2007, 04:58 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Initilize with a cast to int-pointer, and the warning will go away:
Code:
MyUn someVar = {(int*)1};
 
Old 10-18-2007, 05:04 AM   #3
kskkumar
Member
 
Registered: Aug 2005
Posts: 40

Original Poster
Rep: Reputation: 15
Is there any other way to avoid warning? because, i am assigning to integer not to integer pointer. So this is misleading as if i am assigning to an integer pointer.
 
Old 10-18-2007, 06:22 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
You could just initialize the union variable first thing in main() of course:
Code:
typedef union
{
    int *a;
    int a1;
} MyUn;

MyUn someVar;

int main() 
{
    someVar.a1 = 1;
    return 0;
}
But if you really want a global variable initialized, you could also just swap the members of the union in the declaration:
Code:
typedef union
{
    int a1;
    int *a;
} MyUn;

MyUn someVar = {1};
 
Old 10-18-2007, 11:04 AM   #5
kskkumar
Member
 
Registered: Aug 2005
Posts: 40

Original Poster
Rep: Reputation: 15
Thanks. But at some place i will initialize it with address also. So i wnat some statement that can supress my warnings which is equivalent to #pragma warning(disable:<>) in windows.
 
Old 10-18-2007, 04:06 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
As far I can tell gcc has no option to disable warnings except from the command line. If you don't mind breaking compatibility with older compilers you can use the c99 style initialization:
Code:
MyUn some_var = {.a1 = 1};
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
dbx command for corrosponding commands disable or disable on gdb bshankha AIX 0 09-26-2006 09:38 AM
How to disable the warning sound "beep, beep" ICO Red Hat 1 04-04-2006 01:59 AM
Hello/WARNING tn0615 LinuxQuestions.org Member Intro 1 01-09-2006 10:21 PM
disable msec warning loloms893 Mandriva 3 11-21-2005 02:31 AM
what are the services i can disable, also disable ads, banners in konqueror? greythorne SUSE / openSUSE 3 03-16-2005 08:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration